Search API and Solr in Drupal

The Search API Solr module integrates the powerful Apache Solr search platform with Drupal, providing advanced search capabilities, scalability, and performance improvements, making it essential for building robust and efficient search functionalities within Drupal.

This course covers the installation and configuration of Solr and the Search API module, setting up and managing Solr cores, creating and populating Search API indexes, and using Views to create custom search pages and blocks. Additionally, learners will explore advanced features such as facets, autocomplete, and search result excerpts. By the end of the course, you will be equipped to implement and optimize search capabilities of your Drupal sites using Solr.

Key topics

  • Introduction to Solr and its benefits
  • Installing Solr
  • Creating and managing Solr cores
  • Installing and configuring the Search API module and connecting it with Solr
  • Creating and managing Search API Indexes
  • Techniques for populating Search API indexes with content and keeping them updated
  • Using Views for custom search pages
  • Implementing facets and filters
  • Adding features like autocomplete, search result excerpts, and indexing reference fields to improve search functionality
Tutorials in this course
Drupal 8, 9, 10, and 11
More information

Drupal has long provided a built-in search mechanism, so why do we need anything more? In this tutorial, we introduce Apache Solr, a free and open source search service that has several advantages and features beyond Drupal’s built-in search.

In this tutorial, we'll:

  • Define Apache Solr
  • Identify Apache Lucene, the legacy name for Solr
  • List key features of Solr
  • Identify the advantages of Solr compared to Drupal search
Drupal 8, 9, 10, and 11
More information

Apache Solr is not a Drupal module, but a server application like Varnish or MySQL. Before we can use Solr with Drupal, we must plan how we will deploy Solr to our production site.

In this tutorial, we'll:

  • List the requirements for Solr installation
  • Identify when to install Solr on new hardware
  • Describe various installation methods

By the end of this tutorial you should be able to describe a typical Solr install, and begin to list out the various things you'll need to do to install Solr for your environments.

Drupal 8, 9, 10, and 11
More information

Just as you would for Drupal, you should always test your search configuration prior to deploying it to production. In this tutorial, we examine the various ways to set up Apache Solr locally on your system. Then we'll walk through setting up DDEV with Solr for local development.

In this tutorial, we'll:

  • Describe options for running Solr locally
  • List which popular local development environments provide Solr
  • Show how to set up a local, DDEV-based local dev environment with Solr

By the end of this tutorial you should be able to list the different ways that Solr can be installed locally, choose an option that works for you, and see how to get started quickly with DDEV.

Drupal 8, 9, 10, and 11
More information

Solr compartmentalizes itself into cores (or collections if you're using SolrCloud). Each Solr core has its own directory, configuration, and set of search data. While a core can be thought of as an “index”, it is much more.

In this tutorial, we'll:

  • Identify the difference between a Solr core and an index.
  • List the various ways a core can be created.
  • Explain why Search API needs a custom core configuration.

By the end of this tutorial you should be able to explain what Solr cores are, and how to create a Solr core (or collection) that is compatible with Drupal's Search API module.

Drupal 8, 9, 10, and 11
More information

In order for Drupal to work with Apache Solr, we need to add the Search API module. This module provides a generic interface for search backends, including Solr. Furthermore, it adds several features to search without the need for custom code.

In this tutorial, we'll:

  • Describe why Search API is necessary to use Solr with Drupal
  • Identify a Search API server

By the end of this tutorial you should be able to install the Search API and Search API Solr modules, and create the Search API server configuration required to connect Drupal and Solr.

More information

When developing a Drupal site, it is best practice to maintain multiple environments: A production environment for your live site, a stage environment for “next version” development, and your local environment for debugging and creating new features. Solr adds further complexity as we should have a separate Solr server for each.

In this tutorial, we'll:

  • Describe why different Solr servers should be used for each environment
  • Explain why Config Split is not a solution for multiple environments
  • Describe how to use config overrides for each environment

By the end of this tutorial you should be able to override your Search API server configuration with environment-specific settings.

Drupal 8, 9, 10, and 11
More information

While Solr compartmentalizes settings into cores, Search API organizes things into indexes. Each Search API index can have a unique set of settings and crawl a specified list of content types. Search API indexes can be created in the Search API admin interface.

In this tutorial, we'll:

  • Identify a Search API index
  • Describe how an index is related to a Solr core

By the end of this tutorial you should be able to create a new Search API Index connected to a Solr backend.

Drupal 8, 9, 10, and 11
More information

Creating an index alone is not enough. To populate the index, we need to specify the fields necessary to populate the index. Selecting the fields is accomplished in the Search API admin UI.

In this tutorial, we'll:

  • Explain how to select what populates a search index
  • Describe a field boost, and how it is used to customize results

By the end of this tutorial you should be able to add fields to a Search API Index so their content is available for searching, and then instruct Search API to index the content of your site.

Drupal 8, 9, 10, and 11
More information

Reference field types, such as taxonomy term fields, paragraph fields, or plain entity reference fields, refer to a completely separate entity within the site. This makes search configuration complicated as the typical scope of a search crawl is on a per-node (really a per-entity) basis. Fortunately there are known strategies to index these fields with ease.

In this tutorial, we'll:

  • Describe why reference types pose a particular challenge to indexing
  • Discuss the importance of display modes in indexing
  • Highlight how the Rendered HTML Output field can be used to index paragraphs

By the end of this tutorial you should be able to add reference fields to your Search API Index and allow users to search their contents in the correct context.

More information

One of Search API’s key advantages is that custom search pages can be created using Views. This allows a high degree of customization, while relying on a familiar toolset.

In this tutorial, we'll:

  • Describe how to use Views to create a search page
  • Explain search page best practices, including requiring input and no-results text

By the end of this tutorial you should be able to create a page that users can use to search your site's content using the Solr search backend.

Drupal 8, 9, 10, and 11
More information

Drupal has the ability to support multiple Search API indexes within a single installation. While adding a new index is easy, we must understand the implications of creating and using multiple Search API indexes.

In this tutorial, we'll:

  • Identify when to create multiple indexes in Search API
  • Define virtual indexes, and their performance implications
Drupal 8, 9, 10, and 11
More information

Processors allow you to augment your search indexes by performing additional operations before or after the index operation. This can make your search more flexible.

In this tutorial, we'll:

  • Identify what a processor is, and when it can be employed in the search pipeline.
  • List useful processors provided by Search API.
  • Describe how to apply a processor to an index, and why reindexing is necessary.
More information

Excerpts are brief snippets of text displayed in search results. They give context to how the search terms relate to the result. Search API provides support for excerpts out of the box.

In this tutorial, we'll:

  • Identify how to apply excerpts to a search index
  • Describe how to add excerpt display to the search view

By the end of this tutorial you should be able to use the Highlight search processor to add excerpts to search results.

Drupal 8, 9, 10, and 11
More information

Autocomplete provides a brief and quick list of results to the user while typing. While this functionality isn’t available out of the box, it’s easy to add using an additional contributed module, Search API Autocomplete.

In this tutorial, we'll:

  • Describe how to add autocomplete functionality to an existing index

By the end of this tutorial you should be able to add an autocomplete feature to the search query text field.

Drupal 8, 9, 10, and 11
More information

One of the key advantages of custom search is to do more than provide a single, global search box. Filtering allows you to divide results to a subset.

In this tutorial, we'll:

  • Describe how to configure filtering through use of a taxonomy field
  • Explain the disadvantages of this approach, including how it relies on Views to reduce results rather than Solr
Drupal 8, 9, 10, and 11
More information

Filtering results allows us to divide up the result set along one or more dimensions. It’s built in to Search API, but often we need a slightly different approach. Drill-down search or faceted searching allows us to constrain (rather than divide) our result set to one or more dimensions. The contributed Facets module provides this functionality.

In this tutorial, we'll:

  • Describe how facets constrains results to preconfigured dimensions
  • Demonstrate how use of a facet also constrains the possible selections for other facets
  • List the steps for installing Facets module
  • Describe the field types best used for creating facets

By the end of this tutorial you should be able to explain what facets are and how they work in the context of searching a Drupal site's content.

Drupal 8, 9, 10, and 11
More information

Creating a facet in Drupal is rather different from using Facets API in Drupal 7. In the new module, we first create a search view, and then configure facets against target fields in the index. Once created, we must configure the facet UI to appear on target pages using the Blocks UI.

In this tutorial, we'll:

  • List the steps necessary to create a facet using a non-reference field (i.e. boolean, or text list)
  • Explain why facets are displayed using blocks
  • Describe the various facet display modes and uses for each

By the end of this tutorial you should be able to add a facet based on a text list field and allow users to filter search results using the values in the list field.

More information

A powerful facet combination is to create a search Facet on a taxonomy field. This brings several advantages to how your search can be configured and displayed.

In this tutorial, we'll:

  • Describe the additional complexities for using a reference field for a facet
  • Show how to use taxonomy weights to control facet option order

By the end of this tutorial you should be able to add a facet that allows users to filter search result based on taxonomy terms.

Topics
This course appears in the following guides:
Site Administration
Learn how to manage configuration, search, content workflows, performance, and more.

Drupal Site Administration