RSS

How to setup Search API with Apache Solr

18 Apr

By: Ivan Zugec

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.

sapi_image1.png

Next go to the download page and download version 1.4.1.

sapi_image2.png

Extract the files anywhere open up terminal and navigate to the extracted directory.

sapi_image3.png

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.

sapi_image4.png

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

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)”.

sapi_image5.png

Download SolrPhpClient

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.

sapi_image6.png

sapi_image7.png

Modules

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

sapi_image8.png

Configure Search API

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

sapi_image9.png

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.

sapi_image10.png

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

sapi_image11.png

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

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

sapi_image12.png

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.

sapi_image13.png

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.

sapi_image14.png

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.

sapi_image15.png

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.

sapi_image16.png

Search pages

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 the Add search page link.

sapi_image17.png

On the Add search page form enter in the Search name, Index and Path.

sapi_image18.png

On the next page you have a few more options, if you want leave the default options and click on the Create page button.

sapi_image19.png

Go to your newly created search page and test it out.

sapi_image20.png

If your having trouble you can start debugging by watching what appears in the terminal.

sapi_image21.png

Faceted search

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.

sapi_image22.png

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

sapi_image23.png

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

sapi_image24.png

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

sapi_image25.png

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

sapi_image26.png

If you have any problems or questions please leave a comment.

Copy from: http://zugec.com/73-how-setup-search-api-apache-solr#search-api

Advertisements
 
Leave a comment

Posted by on April 18, 2013 in Solr

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: