Update: This tutorial is out-of-date. Please go to Search API’s getting started page for up-to-date documentation.
The Search API is a Drupal 7 search framework module. It allows you to create custom search pages on any URL and integrates with a few search backends.
In this article I’ll show you how to setup Search API with Apache Solr on a mac (10.6).
For more details check out the Search API project page.
If you already have solr setup skip to the Search API section.
Setup Apache Solr
The first thing we’ll have to do is setup Solr locally. Make sure you have Java installed, if your using OSX 10.6 and keep it up to date you should be fine.
To double check run java -version in terminal to see which version is installed.
Next go to the download page and download version 1.4.1.
Extract the files anywhere open up terminal and navigate to the extracted directory.
Solr ships with a built-in web server called Jetty. We’ll use this for our local version. To start up the server go into the example directory and execute start.jar.
cd example java -jar start.jar
Go to http://127.0.0.1:8983/solr/admin to see if solr is working.
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 fromdrupal.org and place them into sites/all/modules:
drush dl entity search_api search_api_solr
Go to your solr root directory and copy/paste the example directory, rename it to drupal (you can call the directory anything).
Copy the schema.xml and solrconfig.xml that ships in search_api_solr and paste it into /drupal/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.
cd drupal java -jar start.jar
Go to http://127.0.0.1:8983/solr/admin to see if solr is working with the new xml files.
Instead of “(Example)” you should see “(search-api-1.0)”.
Go to http://code.google.com/p/solr-php-client/downloads/list 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.
Go to the modules page and enable the Search API, Search pages and Solr search.
Configure Search API
Go to Configuration >> Search and metadata and click on Search API.
There are three steps involved with setting up a solr search page. First we setup the server, then index and finally the search page.
From the Search API configuration page click on the Add server link.
Enter in the Server name and Server description then select Solr service from the Service class select box.
Adjust the Solr service details below if you have any specific requirements.
Once you have finished filling out the form click on Save settings.
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.
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.
Once you have created the index you’ll have to select which fields will get indexed. This could take some trail 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.
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.
Now that we have the server and the index all sorted we have to create a Search Page.
Search API module gives you the ability to create custom search pages on any URL. You are no longer stuck with a single search page on search/node or search/apachesolr_node.
Go to the Search API page and click on the Search pages tab, then click on theAdd search page link.
On the Add search page form enter in the Search name, Index and Path.
On the next page you have a few more options, if you want leave the default options and click on the Create page button.
Go to your newly created search page and test it out.
If your having trouble you can start debugging by watching what appears in the terminal.
Another great feature that the Search API gives you is faceted search.
However this only seems to work with a solr server. UPDATE: Facets do work with database servers. Comment
To get started go and enable the Search facets module.
Once the module has been enabled go back and edit the index that you created. Then select Facets from the dropdown.
For this example I enabled the Content type and Tags > Name block. But you can choose any facet blocks.
Once the blocks are enabled don’t forget to assign them to a region.
Go back to your search page and test out the facets.
If you have any problems or questions please leave a comment.