- Christophe Jossart
Most content from this article might still be relevant but some sections can be outdated.
A walkthrough to join the dots between two posts about setting up Lando for Drupal and Solr for Drupal with Search API, and also a good opportunity to cover all the steps to spin up an evaluation or development environment for this setup.
For the best practices related to Search API and Solr, just install the Solr Search Defaults that ships with the Search API Solr module.
If you need an evaluation and are looking for an automated setup of Umami and Search API, have a look at the excellent Umami demo search repository maintained by Nick Veenhof, there is also a demo site available.
Lando comes with the great benefit to share the server configuration alongside the project, so we have a predictable environment to deploy in production without adding provisioning overhead on the team, especially in the case of more advanced setup like Solr, Varnish, decoupled environments, ... . It also offers faster provisioning compared to other solutions like Vagrant.
brew cask install lando
If Docker is already installed without Homebrew, download the latest version of Lando on GitHub.
Step 1, create a Drupal project with Composer
Here is a one-liner. The community is doing a great job to keep Composer installation methods up to date.
composer create-project drupal-composer/drupal-project:8.x-dev my-project --stability dev --no-interaction
Step 2, add Search API Solr
We are using Search API Solr 2.x, compatible with Solr 7.x.
cd my-project composer require 'drupal/search_api_solr:^2.1'
Step 3, configure Lando for Drupal 8
Initialize Lando with the Drupal 8 recipe and set the webroot as 'web' (default docroot used by the Composer template for Drupal projects).
lando init --recipe drupal8 --webroot web
PHP 7.x is needed for Search API Solr 2.x, open the .lando.yml file and set the PHP version.
config: php: '7.2' webroot: web
Add then the Solr configuration for Search API.
services: search: type: solr:7.1 core: drupal8 config: conf: web/modules/contrib/search_api_solr/solr-conf/7.x
We specify here the desired Solr version and the core name.
The conf definition overrides the default Solr core configuration by the one provided with the Search API Solr module.
At this stage, you are good to go for the provisioning, so let's
Step 4, install Drupal and Search API
The new Umami profile that comes out of the box with Drupal 8.6 sounds like a way better starting point to test Search API, with real content, provided by the demo_umami_content module that is installed with the profile.
lando drush site-install demo_umami --account-name=admin --account-pass=admin --db-url='mysql://drupal8:drupal8@database/drupal8' --site-name=Drupal Solr
Then install Search API Solr.
lando drush en search_api_solr -y
Visit first your project at http://drupalsolr.lndo.site:8000, you should already have a nice Drupal Umami site out of the box!
Uninstall the core search module, that is not necessary anymore. Note that this will remove the Search block provided by the Umami demo. We will replace it later, with the Solr view exposed search block.
lando drush pmu search -y
The project configuration is available anytime via
it will also return your Solr configuration needed in the last step.
Step 5, configure Solr
Login (admin / admin) via http://drupalsolr.lndo.site:8000/user/login
We could start with the Solr Search Defaults module, but there is a configuration dependency with Comments for the Article content type that has been removed by the Umami profile, so it is a good opportunity to create our own configuration from scratch.
This is not a production or full Search API setup, just a minimal configuration to get our demo running and understand how it is build.
Head to Configuration > Search API
Add a server with the following values:
- Server name: Solr Server
- Backend: Solr
- Solr Connector: Standard
- Solr host: search
- Solr core: drupal8
Leave all the other default values. The host and the core values were defined earlier in the .lando.yml file.
Go back to the Search API configuration and add the index.
Set the following values:
- Index name: Content index
- Data sources: Content
- Server: Solr Server
Let all the other values, save and do not index your content yet as there will be other configuration changes.
Click on the Fields tab then 'Add fields', and add the following ones:
- General > Rendered HTML output, set the 'Search index' value for each View mode
- Content > Title
Click on 'Save changes' and go back to the View tab, then click on 'Index now' (/admin/config/search/search-api/index/content_index).
Add now a view to display the content index (Structure > Views > Add view), with these values:
- View name: Content index
- View settings / Show: Index Content index
- Pages settings: Check 'Create a page' and set the 'Path' to search/content
- Pages settings: use the Display format 'Unformatted list' of 'Rendered entity'
Click then on 'Save and edit'.
On the Filter criteria section, add 'Fulltext search' then check 'Expose this filter to visitors'.
On the Advanced section, set the 'Exposed form in block' to 'yes' then save your view.
We will now replace the core search block that was removed previously.
Go to Structure > Block layout then click on 'Place block' for the Header and choose 'Exposed form: content_index-page_1'
Go back to your site, you now have a functional Solr search with Umami.
Bonus: here is a Lando configuration example with a few more settings like phpMyAdmin and Mailhog, two other common services for a Drupal development environment. lando.yml