Drupal 8 and solr with search api - part 1 - Installation and configuration

Submitted by nmeegama on Fri, 06/16/2017 - 09:49

Implementing a solid search functionality is very important for website developers. In this blog I will discuss

  • What the core search module in Drupal 8 can do
  • What contributed modules we can use
  • Using Solr woth Drupal 8
  • Other alternatives


What the core search module in Drupal 8 can do

The core search module basically has the same functionality as Drupal 7 but there is a extended functionality where you can create search pages and configure how the content is ranked to a certain extent. Also you will have a Advanced search similar to Drupal 7

core search

Core search module functionality is limited but with the addition of contributed modules we can extend the functionality and build great features.

What contributed modules we can use

 Search API is the best module out there to improve and extend Drupal 8's search functionality.  But Search API alone may not make any sense to you just by enabling it (The search API module itself is a framework) unless you use backend plugins available for the Search API. I am not going to describe all of the backend plugins in this list In fact I am going to walk through a plugin that is not in the list which is Search API Solr Search. This  module provides a Solr backend for the Search API module. This module basically create a communication link between Drupal Search API and Apache Solr. Apache Solr is an open source enterprise search platform built on Apache lucene. Basically Solr allows the us to create indexes of our data in order to create more efficient and fast search solutions for our applications. The Search API Solr Search plugin/module basically does 2 things.

  1. Communicates with Solr about what kind of indexes Drupal wants to create and what fields to use to create the indexes OR what facets to create and what fields to use as facets.
  2. Communicates with Solr to get results for when user queries with specific keywords.


NOTE: In order to enable multilingual support use the Search API Multilingual Solr search module.

Using Solr woth Drupal 8

  1. First we need to download Apache Solr server locally.
    • First download the latest Solr version that is compatible with Drupal 8 which is 6.x from here. The recommended version I would say is 6.6.0.
    • Unzip the folder

      Apche solr root

    • Create the following folders inside the solr installation (in the server/solr folder )
      • Creating a new solr core

      • New solr core folders

  2. Install  the Search API Solr Search module. Use the following command to install the module
    1.  composer require drupal/search_api_solr

                   Drupal Solr module installation 

    2. Now copy the configuration files in the modules /solr-conf/$SOLR_VERSION (version should be 6.x) folder in to $SOLR/server/solr/$CORE/conf.

      Solr module

        copy conf folder


Now inside the $CORE folder you crated you have to tell SOLR about the new core by creating a core.properties file:

Solr core properties file

Add the following line to the file 

"name=$CORE" $CORE should be the name you gave the folder in this case its "drupal8"

core properties file

After this step start the Solr server again. GOTO the  $SOLR root and issue the following command

bin/solr start

         start solr

  1. Tell Drupal how to connect to the local Solr server (Adding a server for the Search API)
    1. Got to /admin/config/search/search-api/add-server if the above installation step is successful then you will get a form to tell Drupal about your Solr server. Fill in the details accordingly. If the inserted details are correct you should get the a screen like the following. 

      server success

      NOTE: The default solr port would be 8983 but in case you have changed it then the value in the "" field also has to change. I only had to put in a "Server name" value all others were left as default
  2. Configure how to create the indexes on Solr
    1. GOTO /admin/config/search/search-api/add-index 
      • Enter a name for the index
      • Select the data sources. As you select the data sources, a configuration form for each data source will appear below. By default for each data source all bundles are selected. For this example I ended up selecting all data sources but did nothing in the configuration forms. So by my selection everything in my web site should be aligned  for indexing.
      • For the "Server" we need to select the server that we create in the above step. 
      • All other fields should be left as default.
      • Once saved we end up in a screen as below
        index save
      • Once thats done Click on the "Index now" button.
      • All entites should be indexed.
  3. Test the configurations
    • Now we would have to create the index by selecting what fields to index so that we could test the search function. Await part2 of this blog post for the steps on creating a view to test the search functionality.... To be continued ....