Apache Solr is a very popular open source search platform, based on the Java Lucene Library. Solr is very stable, scalable and reliable and provides a wide set of core search functions. Solr creates an index of the available documents and then you can query Solr to return the most relevant ones for your search.
This tutorial will deal with the integration between Drupal and the Solr platform. Before you begin, you will need to have installed Apache Solr on your server.
Step #1. Checking the Status of the Solr Server
- Open the Terminal application in your system and type:
service solr status
You’ll see an output with the label Active: active (exited). That means Solr is working properly. By default, Solr works on port 8983. This way, you can take a look at Solr’s user interface by typing localhost:8983 (or whatever your host is called).
Step #2. Installing the Drupal Module
To install this module, you have to use Composer, otherwise there will be unresolved dependencies and it won’t work.
- Open your Terminal application and type:
composer require drupal/search_api_solr
Step #3. Configuring Solr
In order to work with the Solr platform, you have to create a collection. A collection is basically a logical index that’s associated with a config set.
- Open your Terminal window and type:
sudo su - solr -c "/opt/solr/bin/solr create -c firstcollection -n data_driven_schema_configs"
This command will vary, depending on where Solr is installed. In my case it’s in the /opt folder of my Ubuntu system. However, the collection will be created in another directory.
- Take a look at Solr’s dashboard and select "Core Admin".
- Check that the collection has been created and its location.
- Become the root user.
- Locate yourself in the collections folder of Solr, which is located at the /var directory in an Ubuntu based system.
- Rename the default conf file.
- Copy the configuration file called 7.x inside the installed Solr Search API module and rename it to conf.
cp -R /var/www/your_site/docroot/modules/contrib/search_api_solr/solr-conf/7.x conf
- Change owner, group and permissions for this new folder.
- Restart Solr.
- Exit session as root.
Step #4. Enabling the Search API Solr Module
- Click Extend > Uninstall and look for the Drupal default Search module. This module has to be uninstalled to avoid performance issues. Select the module and click "Uninstall".
- Confirm the Uninstall process by clicking the blue "Uninstall" button once again.
- Click the List tab and enable the "Solr Search Defaults" module, this module provides the initial default configuration.
- Click "Install". The Solr Search module will be enabled automatically.
Step #5. Configuring the Search API
- Go to Configuration > Search API.
- The Server and Index configurations were provided by the Solr Search Defaults module.
- Click the "Edit" button to configure the Server.
The only thing you have to do is to change the name of the Solr core to the name of the core you created previously.
- Scroll down and find the Solr core label.
- Change the name of the core to firstcollection.
- Click "Save".
Server and index are ready to use.
- Go to Extend > Uninstall.
- Look for the Solr Search Defaults module, and uninstall it. For performance reasons, the provided configuration is already stored.
Step #6. Testing the Search API Solr Module
By default, the Search API Solr module provides a view with a search box where you can type the text you’re looking for. The search page is located at:
- Type in a keyword and hit the "Search" button.
- If you see a list of results (the word has to be in the content of course) you’ve successfully configured Search API Solr. Congratulations!
This tutorial showed the basic configuration of the Search API Solr module to integrate Drupal 8 with Apache Solr.
I recommend exploring the available configurations and reading Solr’s documentationn. This will give you a better idea of all options available when configuring the search functionality of your sites.
Thanks for reading, please leave your comments below.