Skip to main content
Last Reviewed: December 13, 2022

Using Solr 8 on the Latest Version of Drupal

Information on using Pantheon Search with Solr 8 on the latest version of Drupal


Pantheon Search with Solr 8 gives the latest version of Drupal web teams a high-performance search index integrated with Integrated Composer's one-click updates.

Solr 8 Features

Pantheon Search with Solr 8 includes multiple built-in features to make scalable, high-performance search more customizable, including the following:

  • Media/rich content type indexing for attachments such as PDFs and Word documents

    • Solr has the ability to store information about document relationships in the index. The stored information can be used for queries and can also return child pages in nested form if the relationship is properly stored in the index.
  • Multiple language support

    • Use Solr’s stemming and language identification libraries that allow for the searching of multiple languages using separate fields, the same field (separate Solr cores), or the same field and Solr core.
  • Drupal Views integration for building search results pages and custom search forms.

  • Partial string search.

For more information on Solr 8 features, refer to the Drupal Search API Solr documentation.

Custom Processors

Search API module processors provide a variety of configuration options for your Pantheon Search results, like boosting results based on dates, taxonomy terms, or specific content types, controlling access to content based on permissions, and adding highlighted excerpts to results.

Refer to the Search API module processors documentation for details.

Before You Begin

Drupal Site Setup

Pantheon Search with Solr 8 can be used on Drupal sites. You can set up a new Drupal site or visit the Drupal upgrade and migration guide to create a Drupal site.

Prepare the Local Environment

Ensure you review our documentation on Git, Composer, and Terminus, and have them installed and configured on your local machine. Pantheon requires Composer 2 at a minimum.

  • Mac users can use Homebrew to install Git, Composer, and PHP 7.4, along with their required dependencies. Restart the shell or terminal environment after entering the following command:

    brew install git composer [email protected]
  • Windows users should install the following dependencies:

    • Composer

    • Git

    • The XAMPP development environment or a similar package might need to be installed to satisfy some dependencies.

Pantheon Environments

Each Pantheon environment (Dev, Test, Live, and Multidevs) has its own Solr server. Indexing and searching in one environment does not impact any other environment.

As a Limited Availability participant, your will need to manually enable access to Solr 8 for your site, for each environment in which you would like to create an index (Dev, Test, Live, and Multidevs).

Enable at the Site Level

You must enable Pantheon Search at the site-level and add the Apache Solr Index Server. This can be done by using either the Terminus CLI or through the Site Dashboard.

Using Terminus

Enter the following command. Replace $SITE with the specified name of the site:

terminus solr:enable $SITE

Using the Site Dashboard

To enable at the Site level follow the following steps:

  1. Navigate to the site and environment you would like to configure.

  2. Click Settings.

  3. Click Add Ons > Apache Solr Index Server: Add.

Configure the Version

You must configure the pantheon.yml for the platform environment after you enable the Apache Solr Index Server.

  1. Specify the Solr version in the pantheon.yml before you install the Drupal search module to avoid incompatibilities.

    • Currently, Solr 8 is supported for Drupal sites. Specify Solr 8 as the search version for Drupal sites by adding the following to pantheon.yml:

      pantheon.yml
      search:
        version: 8
  2. Push the changes to pantheon.yml.

    • A confirmation message indicating the file has successfully updated is returned in Git. The platform may take a few minutes to update, especially if you use Pantheon’s Integrated Composer to update your site modules.

For more information, refer to the documentation on Specifying a Solr version

Verify pantheon.yml is Configured Correctly

After you specify the Solr 8 version in the Dev environment of your Drupal site, verify that the environment is configured to use Solr 8. The configured Solr environment will have several PANTHEON_INDEX_* variables, one of which will be PANTHEON_INDEX_PORT. If Solr 8 is configured correctly, the PANTHEON_INDEX_PORT value will be 443. If any other value is displayed, your site is still configured to use Solr 3.

  1. Run the command below:

    terminus drush SITE.ENV -- ev "phpinfo();" | grep PANTHEON_INDEX_PORT
  2. Confirm that the PANTHEON_INDEX_PORT value is 443. The output from the command above should look similar to the example below.

    terminus drush solr8-sandbox.dev -- ev "phpinfo();" | grep PANTHEON_INDEX_PORT
    [warning] This environment is in read-only Git mode. If you want to make changes to the codebase of this site (e.g. updating modules or plugins), you will need to toggle into read/write SFTP mode first.
    PANTHEON_INDEX_PORT => 443
    $_SERVER['PANTHEON_INDEX_PORT'] => 443
    $_ENV['PANTHEON_INDEX_PORT'] => 443

Install and Enable the Search API Pantheon Module

To install and enable the Search API Pantheon Module, access to Solr 8 must be enabled and pantheon.yml should be configured to use the Solr 8 version as described in the steps above.

Dependencies

Composer automatically installs dependencies as part of the Search API Pantheon Module drupal/search_api_pantheon:^8.

The commands specified in the next section install the following dependencies:

  • Solarium is a Solr client library for PHP and is not Drupal-specific.

  • Search API is Drupal's module for indexing content entities.

  • Search API Solr makes search API work with Apache Solr. Composer manages which version will be installed.

  • Guzzle version 6 is standard with Drupal Core 8 or 9.

Install the Search Module

To install the Search API Pantheon module, switch to your local machine.

  1. Clone the Git repository for the desired environment from the Pantheon Site Dashboard.

  2. Enter the following command in the terminal to run composer install:

    composer install
  3. Add the Search API Pantheon module as a required dependency:

    composer require drupal/search_api_pantheon:^8 --prefer-dist
  4. You should now have the Search API Pantheon module installed along with its dependencies. You can run git status to verify that only composer.json and composer.lock were modified.

  5. Commit and push the changes, Integrated Composer will take a few moments to install these on your site.

You can enable the search_api_pantheon and search_api_pantheon_admin modules from the command line using Terminus and Drush.

Enter the following command, replacing $ENV with the environment:

terminus drush $SITE.$ENV -- pm-enable search_api_pantheon search_api_pantheon_admin

You can also enable the modules from the site’s Extend page located in /admin/modules.

Add Search Index

Enable the Search API Solr Admin module.

Navigate to Configuration > Search & Metadata > Search API within Drupal’s Admin interface. The server labeled Pantheon Search should be displayed, and the status should indicate the server has been enabled.

  1. Click Add Index to configure a new search index.
  2. Give the index a name, and select the datasources that should be indexed. For each datasource enabled, select the desired bundles, languages, and options.
  3. Select Pantheon Search as the Server.
  4. In the Index Options panel, ensure Index items immediately is checked.
  5. Click Save to add the new index.

The Index status page should indicate that the newly created index was successfully saved.

Add Fields to the Index

Follow the steps below to add fields to your new index.

  1. Click Fields > click Add fields.
  2. Click Save changes when you are finished.

Index Content

Follow the steps below to index existing content.

  1. Click Index now on the View tab of your index’s Overview page.
  2. Click Search API to return to the Search API overview page located in admin/config/search/search-api.

Both the server and index you just created should be displayed on the page.

Post the Schema

  1. Click on the server’s name to view the server > select the View tab to display the server connection information, schema version, and indices.
  2. Select the Pantheon Search Admin tab to save and post the schema information.
  3. Enable the Execute Pantheon Search admin task permission for users who need access to the Pantheon Search Admin tab.
  4. Click Post Solr Schema to send your custom schema to the Solr 8 server.
    • The server responds with a 200 - OK status for each schema file posted.

Troubleshooting Pantheon Search with Solr 8 for Drupal

Incorrect Solr Version

This error is indicative of Solr 3 being active when Solr 8 is expected:

Server index status - Error while checking server index status: An error occurred while searching, try again later.

When running drush sapi-search commands, you may also see:

Apache Tomcat/7.0.68 - Error report HTTP Status 400

This can be fixed by updating pantheon.yml to use Solr 8.

Diagnose Issues

The diagnose command drush search-api-pantheon:diagnose (sapd) checks the Search API install and returns an error for any part that is not working.

The drush search-api-pantheon:select (saps) command runs the query against the Solr server. It is recommended that you use ?debug=true on any Solr page to allow a query to pass.

Deploy an Updated config.zip to your Solr Server

If the Search API Solr displays the following after the Search module is installed:

It is advisable to download and deploy an updated config.zip to your Solr server.

This message can safely be ignored. It resolves once a search index has been created and the schema files have been posted.

Running Composer with a Lenient Endpoint

If you are using the Lenient endpoint, you may encounter an error when running Composer that resembles the following text:

Package drupal/search_api_pantheon exists in composer repo (https://packages.drupal.org/8) and composer repo (https://packages.drupal.org/lenient) which has a higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.

This occurs because both repositories contain a package called drupal/search_api_pantheon, and Composer cannot discern which package is being requested. Change the repositories definition by adding a definition for the Lenient repository in the site's packages.json file with an explicit exclude argument:

packages.json
"repositories": {
    "lenient": {
        "type": "composer",
        "url": "https://packages.drupal.org/lenient",
        "exclude": [
            "drupal/search_api_pantheon"
        ]
    },
    "drupal": {
        "type": "composer",
        "url": "https://packages.drupal.org/8"
    }
}

Fatal error: Cannot redeclare config_get_config_directory()

This error occurs after installing search_api_pantheon for Drupal using Composer. If you receive this error, you should switch to the Drupal Composer-managed Upstream. See Switch Your Custom Upstream for instructions on how to do this.

Reloading Solr Core

Reloading Solr Core would be helpful if synonyms or other Solr config that you've recently posted isn't reflecting even after reindexing your site. You can follow this steps on how to enable the Reload Core in your Search API configuration:

  1. Go to /admin/modules
  2. Enable Search API Solr Admin
  3. Go to /admin/config/search/search-api
  4. Click the server you want to reload
  5. You'll be able to see the Reload Core button and you can simply click and confirm to reload
  6. Reindex the site to apply any changes