Configure Search API Solr with the Umami profile using Lando

Objective

Lando comes with the great benefit to share the server configuration alongside the project. 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.

  • Instead of installing solr in the system and run multiple lines of code just add one line code inside Lando file. Using Lando it is easy to change version according to your requirement.
Recipe Type
Status
Proposed
Drupal Version
Recipe Tags
Steps to Build
  • Create a Drupal project with Composer

    composer create-project drupal-composer/drupal-project:8.x-dev my-project --stability dev --no-interaction

  • Add Search API Solr
    cd my-project
    composer require 'drupal/search_api_solr:^2.1'
  • configure Lando for Drupal 8
    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.
    Define-php-value
  • Add then the Solr configuration for Search API. You can check Lando solr supported version here.define-solr-inside-lando
  • Give your app the name then start Lando
    lando start
  • Install Drupal and Search API
    lando drush site-install demo_umami --account-name=admin --account-pass=admin --db-url='mysql://drupal8:drupal8@database/drupal8' --site-name=Drupal Solr
  • Install Search API Solr
    lando drush en search_api_solr -y
  • Uninstall the core search module, that is not necessary any more. 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
    Search-umami
  • The project configuration is available anytime via
    lando info
    it will also return your Solr configuration needed in the last step.
  • configure Solr
    • Head to Configuration > Search API
    • Add a server with the following values
      Server solr configuration
    • Leave all the other default values. The host and the core values were defined earlier in the.lando.yml fileSolr-config
    • Go back to the Search API configuration and add the index.
      Add-index
    • Set the following values.
      index-value
    • After creating the index, 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:Add-field
    • General > Rendered HTML output, set the 'Search index' value for each View modeAdd-render-html
    • Content > Titlerender-html
    • 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-details
  • Click then on 'Save and edit'.
  • On the Filter criteria section, add 'Fulltext search' then check 'Expose this filter to visitors'.Filter
  • On the Advanced section, set the 'Exposed form in block' to 'yes' then save your view.expose
  • 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'
    search-block

Done, yay!

Go back to your site, you now have a functional Solr search with Umami.

Optional Steps

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-extra

Supporting Organizations
Participants