Solr Search Integration With Drupal 7 On Ubuntu

Solr search with Drupal 7

Solr is a standalone enterprise search server with a REST-like API. It is a Java-based application that provides an API for interacting with Apache Lucene via HTTP to facilitate the creation of excellent applications for performing full-text content searches, with a special focus on internet-based search applications.

It offers,

  • Powerful Extensions
  • Faceted Search and Filtering
  • Advanced Configurable Text Analysis
  • Performance Optimization
  • Advanced Storage Options

It becomes an obvious choice because compared to Drupal’s default modules, it’s insanely fast. It helps you improve both speed and relevancy of search result for Drupal site. I will now present a step-by-step guide on how to install necessary tools and integrate Solr with Drupal 7.

-2. Install Java on Ubuntu with Apt-Get

First, update the package index:

sudo apt-get update

Then, check if Java is not already installed:

java -version

If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:

sudo apt-get install default-jre

This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:

sudo apt-get install default-jdk

-1. Install Solr using apt-get (easy way) on Ubuntu 14.04

 

sudo apt-get -y install openjdk-7-jdk

mkdir /usr/java

ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default

 

We can now start the real installation of Solr. First, download all files and uncompress them:

 

cd /opt

wget http://archive.apache.org/dist/lucene/solr/4.7.2/solr-4.7.2.tgz

tar -xvf solr-4.7.2.tgz

cp -R solr-4.7.2/example /opt/solr

cd /opt/solr

java -jar start.jar

 

Check if it works by visiting http://YOUR_IP:8983/solr

0. How to setup Search API with Apache Solr

Setup Search API

To get Search API working with solr there are a few thing we'll have to configure with solr. First go and download the following modules from drupal.org and place them into sites/all/modules:

  1. Entity
  2. Search API
  3. Search API Solr search

drush dl entity search_api search_api_solr

Configure solr

Copy the schema.xml and solrconfig.xml that ships in search_api_solr and paste it into /solr/conf. It's fine to override the existing xml files just make sure you create a backup.

Now go ahead and test solr with the new xml files.

java -jar start.jar

Go to see if solr is working with the new XML files.

Download SolrPhpClient

Go here and download (Only works with r22 Solr PHP Client (Built 11/09/09 from r22) ) the php solr library and place it in the seach_api_solr directory.

Solr search with Drupal 7

Modules

Go to the modules page and enable the Search API, Search pages and Solr search.

Solr search with Drupal 7

Configure Search API

Go to Configuration >> Search and metadata and click on Search API.

Solr search with Drupal 7

There are three steps involved with setting up a solr search page. First we setup the server, then index and finally the search page.

Setup server

From the Search API configuration page click on the Add server link.

Solr search with Drupal 7

Enter in the Server name and Server description then select Solr service from the Service class select box.

Solr search with Drupal 7

Adjust the Solr service details below if you have any specific requirements.

Once you have finished filling out the form click on Save settings.

Solr search with Drupal 7

Setup Index

Once the server has been setup, the next thing we have to do is configure the index. Click on the Add index from the Search API configuration page.

Solr search with Drupal 7

In the Add index form fill out the Index name and select which entity type you want to index and select Solr from the Server select box.

Solr search with Drupal 7

Once you have created the index you'll have to select which fields will get indexed. This could take some trial and error depending on your data. In the example that I'm using I have add the "main body text" and "Tags" from the Add related fields.

Solr search with Drupal 7

After you have selected which fields get to be indexed, you'll be directed to the Workflow page. On this page you can specify extra data alterations and processors to the index data. For this example we'll keep that page empty.

The final item for the index is to actually add data into the solr index. Click on the Status tab and click on the Index now button.

Solr search with Drupal 7

1. Faceted Search

Another great feature that the Search API gives you is faceted search.

To get started go and enable the Search facets module.

Solr search with Drupal 7

Once the module has been enabled go back and edit the index that you created. Then select Facets from the dropdown.

Solr search with Drupal 7

For this example I enabled the Content type and Tags > Name block. But you can select any facet blocks.

Solr search with Drupal 7

Once the blocks are enabled don't forget to assign them to a region.

Solr search with Drupal 7

Go back to your search page and test out the facets.

Solr search with Drupal 7