Drupal, Search API and Apache Solr with Homebrew on OS X

This is a short, no-frills guide to installing Apache Solr with homebrew on OS X, then using it with the Search API Drupal modules. Posted by Thomas Sutton on May 13, 2014

Installing Apache Solr with Homebrew on OS X and using it with the Search API modules for Drupal is pretty easy. This article will run through the process and includes a few tweaks to make things more convenient for those like me, who do this on different projects fairly regularly.

Installing Apache Solr

Apache Solr is a bit of a monolith (if you use it like most people I’ve seen): you just download it and unpack it somewhere. Indeed, this is exactly what the homebrew formula does. Run this command to get it installed:

It also includes a handy shell script to start Solr using a configuration directory you specify on the command line. Alas, it doesn’t set a few properties which would be nice to have available in our Solr configuration files. But it is a very simple shell script, and we have text editors!

Edit the solr shell script brew installed (you can use which solr to find it) and make it look like this:

(The 4.7.2 part will change depending on the version of Solr you have installed; make sure it’s correct.)

We’ve adding two new properties specify where to find the JAR files, etc. that come in the Solr distribution. We’ll use these when we’re tweaking the Solr configuration files that come with the Drupal modules.

Installing Drupal

Now that Solr is installed, start a new Drupal site and install the Search API modules. I’m a command line person, so I do something like this:

Start a new Drupal project, and download and install the Search API module and all its friends:

Building a Solr core for Search API

Now lets create a new Solr core for Search API to use. We’ll start with one of the example configurations that come with Solr (watch out for the Solr version number in this path):

This configuration includes a single Solr “core” called collection1. We’ll duplicate that, then drop the Search API Solr configuration on top of it.

Now to tweak it. First, give the new core it’s own name so that Solr can identify it correctly:

Then update the solrconfig.xml file that came with Search API Solr to use the solr.dist.dir and solr.contrib.dir properties we added to the solr shell script above. Basically replace any mention of ../../dist/ in your solrconfig.xml file with ${solr.dist.dir:../../dist/}. This says “use the configured value for solr.dist.dir or, if there isn’t one, ../../dist/”. It should already be done for solr.contrib.dir but you might like to double check, just in case.

If you want to use any optional/non-core features you’ll need to update the <lib> tags (these are the main places you’ll need to make the solr.dist.dir change) to use the correct JAR file names.

I’ll be using the extraction functionality to index the content of PDF and other files, so I needed to uncomment and correct the tag for solr-cell-\d.*\.jar:

Running it

Now go configure your Drupal site to use your new Apache Solr instance. You should configure Search API to communicate with Solr at http://searchapi.dev:8983/solr/${PROJECT_NAME} (you should put the real value here, not the variable name). Then enable an index, configure it, and build some search functionality!

This post was published on May 13, 2014 and last modified on September 4, 2020. It is tagged with: howto, drupal, search, solr, homebrew.