How to Set Up & Configure Apache Solr for Drupal

Submitted by Brandon Cone on 04/19/2013 - 11:01:am

Standing up an Apache Solr instance on your server can be a great boost to your site's UX.  Quicker search results are a great boost to higher conversions and a more positive experience of your site. However, setting up and configuring your Solr instance can be a little intimidating.  Here are some tips we have found helpful when setting up Solr for some of our clients lately.

1. There's a really handy post to installing and starting your Solr server from Reality Loop here.  This will provide a good starting point to getting your Drupal site integrated with Solr.

2. Set up a conf directory for your Solr instance within your repository.  We use Git for version control here and doing this allows all developers to use the same Solr configuration.  You simply need to symlink the conf directory within the Solr instance to this location.

3. Set up this conf directory to be for Solr version 4.x and make sure it includes all the necessary files (protowords.txt, etc).

4. If you are doing any multiple field references you will want to modify the Solr field mappings.  The Drupal apachesolr module implements hooks to enable you to do this without modifying the solrconfig.xml file within your confi directory.  Here is an example of how we did this to enable multiple taxonomy term references to be indexed properly:

 

  1. /**
  2.  * Implements hook_apachesolr_field_mappings_alter().
  3.  */
  4. function my_module_apachesolr_field_mappings_alter(array &$mappings, $entity_type) {
  5.   $mappings['taxonomy_term_reference']['multiple'] = TRUE;
  6. }

 

5. Download and install the facetapi_bonus module.  This allows you to filter the contents of your Solr facets as well as alter them using a hook implementation.

6. After you ensure that your Solr server is up and running, you can set up your Solr index from admin/config/search/apachesolr.  This will enable you to configure your facets from admin/config/search/apachesolr/settings/Solr/facets

7. If you use context, you will want to configure your search page to enable facets to "Show enabled facets' blocks in their configured regions". 

8. To show your facets on no-search pages (e.g. using context), you need to enable your facets to "show facets on non-search pages."  An important note that even if they are place via context, if this is not enabled and the page in question is not listed, the facets will not display.