Wednesday, February 6, 2013

Drupal with Apache Solr

Apache Solr is a search platform that can be used as a replacement for core content search and provides extensive features and excellent performance. An increasingly popular use case for Solr is integration with the Drupal content management system. With BitNami Drupal and BitNami Solr stacks, it is very easy to configure Drupal to use the Apache Solr search engine.

BitNami Drupal already ships the Apache Solr Search Integration module. If you are using your own Drupal installation, install this module before continue.

Once you have Drupal running with the Solr module, the next step is to setup a server for Apache Solr. You can install it in the same machine or in a different machine, which is probably a good idea to improve performance.

Download and install BitNami Solr Stack. You can download free installers for Windows, Linux or OS X, download a virtual machine or deploy a cloud image already configured for Windows Azure and Amazon Web Services. It is important to use a compatible version with the Apache Solr Search plugin for Drupal. At this moment it is not compatible with Solr version 4, so make sure that you download version 3 (the latest stable version is 3.6.1).

Once the Apache Solr server is running, you can see something similar to this.

Apache Solr version 3.x
To configure the Solr server properly for Drupal, copy the schema.xml and solrconfig.xml files from the Solr Search module. You can find these files in the "drupal_application directory/sites/all/modules/apachesolr/solr-conf" folder. Copy these files into the "solr_installation_directory/apache-solr/solr/conf" directory and restart the Solr server.

$ cd solr_installation_directory
$ ./ctlscript.sh restart solr

In the Solr admin panel, you should now see something like  "drupal-3.0-0-solr3". If this is the case, everything is ready on the Solr side.

Note that Solr is running in the 8983 port by default. If you are using a BitNami virtual machine or a cloud image check that this port is open and accessible from the Drupal machine. You may need to change your firewall settings for this.

Now, it is time to configure the Drupal application. Go to "Modules", "Search toolkit" and enable both Apache Solr framework and Apache Solr search.

Apache Solr module

Click on the "Modules", "Solr Search Framework" configuration button and add a new connection:

URL: http://Solr_IP:8983/solr
Name: Remote Solr

Then, test the connection. If it is not able to contact the Solr server, check that the IP address is correct and the 8983 port in the machine running Solr is reachable. 

Now, configure the Drupal application to use Solr by default. Go to "Configuration", "Search settings" and enable Apache Solr search in the default search modules. If you have already content in your Drupal installation, you can re-index your site from there. This could take some time depending on the size of your existing content. 

That's it! Test the setup trying to use the search block in your site to see the results. If you run into  problems, feel free to ask any questions in the BitNami Q&A site and we will do our best to help you.