How to setup Search API with Apache Solr
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 from drupal.org and place them into sites/all/modules:
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
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)”.

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.


Modules
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.
Setup server
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.

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.

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.

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.

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.

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.

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.
Comments
Great write-up!
If you don't object, I'll link to this article on the project page. I'll probably create a handbook page detailling this soon – can I use your screen shots for those? Looks really great!
One correction, though: Facets already also work with database servers, and facets support for Xapian servers is (as far as I know) planned, too.
Thanks
Absolutely link to this page :)
Also thanks for the correction.
great article
Hi, i wanted to say thank you so much, what a great tutorial, this is one of the most helpful and interesting post i have ever read, thanks again.
PHP client
This was an excellent walkthrough. One item of note: This only works with r22 of the SolrPhpClient. r60 generates errors.
Thanks
Post has been updated.
Outstanding Walk-Through ...
Thanks very much for this. I was dreading trying to figure it out on my own but your instructions are easy to follow and simplified to make it a much easier journey. VERY GOOD STUFF!
Ivan Kudos
You directed me to the search API module in Drupal. You didn't tell me about this guide :-)
I messed around with all kinds of things, I now read how too, in this guide.
I just set up Solr 3.3.0 on my local tomcat windows machine and finished setting up the simple search form. And YES YES It's finding "Jobs" Cool man I couldn't be happier.
Finally!! Something that worked for me!
Just wanted to say that your tutorial is a godsend!! I have been googling this forever and trying various tutorials -- they've all worked up to a point, but I could never get the facets working. With yours, I finally can! Much gratitude from a complete drupal newbie. THANK YOU.
HTTP authentification
This is a brilliant tutorial - easily the best I've seen for this.
There's only one thing missing (from this and pretty much every Solr tutorial, especially the flimsy Drupal docs), which is the basics of how to secure Solr, in particular how to set up HTTP Authentification.
This depends on whether you're using a Tomcat or Jetty version of Solr (I believe Jetty is the default). It's Jetty if you have a file jetty.xml (usually .../[solr directory]/example/etc/jetty.xml ), and it's tomcat if you have a file WEB-INF/web.xml (could be various places on your system, try running find / -name "web.xml" )
Here's a good, well written guide on how to set up basic HTTP authentification for apache solr in Jetty, and here's a guide on how to set up basic HTTP authentification for Tomcat apache solr.
Thanks for the links. :)
Thanks for the links. :)
it would be great if someone
it would be great if someone could post a way to autostart jetty on system boot/startup. i found a way but thats suboptimal.
i created a shellscript containing the manuel command and call that on startup (update-rc MYSCRIPT defaults)
Found this on stackoverflow.
Found this on stackoverflow.
http://stackoverflow.com/questions/2150767/how-to-start-solr-automatically
Awesome!
Nicely written! I love full-fledged how-tos like this. The apache solr and search apis are SUPER powerful. Love it!
Default empty search
Hi,
and thank you for this how-to.
Do you (or anybody else) know how to get the "start-page" of search to view all data? What I mean is that when a user first get to the search page I want to show all data to the user.
Search API views page
If you create a search pages using views (search_api_views). You can set it up to display default results when they land on the page.
thanks for this great
thanks for this great tutorial.
I am using the regular mysql database service which now should provide faceted searching....
Even though I think I make everything ok, I end with facets with no items...would you have a clue on what I could have missed?
I haven't used Search API
I haven't used Search API with the database backend. Try using solr and see what happens.
How to use Acquia Search with Search API?
I need to use Acquia search with my Search API module, but I can't figure out how. I tried all combinations but with no luck. If somebody succeeded, could please explain me how??
THANKS!
I don't think Acquia search
I don't think Acquia search supports Search API, I could be wrong. :) Contact Acquia and find out.
Acquia SOLR
Please poke them to support it. I've asked them as well, and the more people ask for it, the earlier they will adopt it. The problem is that they need to support a specific schema.xml.
Facets blocks
I followed your tutorial. Great now I have my own solr drupal on my mac :D
Only when I place the Facets in blocks they don't show up untill I enter a keyword that is in the title of the a node and press search. any idea how this is posible?
Do I need to change something so that opening the page I created is showing all results? and if so how?
search views
found a sollution for my problem :)
Using search views and creating a new view I now have nodes with Facets in blocks on the side of the page
thanks a lot
First thanks a lot for those technical terms along with images. you made my day. I do found one more similer blog which worked for me hope this helps others http://www.phptechi.com/how-to-configure-solr-with-php.html
Hi,
Hi,
I am not able to index my content…
in logs,,error is
Indexing failed on one of the following entity ids: node/1, node/2
“400″ Status: Bad Request: Bad RequestApache Tomcat/6.0.33 – Error report HTTP Status 400 – ERROR:unknown field ‘site’type Status reportmessage ERROR:unknown field ‘site’description The request sent by the client was syntactically incorrect (ERROR:unknown field ‘site’).Apache Tomcat/6.0.33
pls help…
Can't connect to Solr
It looks like Search API can't connect to Solr. Make sure you can access the Solr admin page first.
Search API Error
Hi,
I installed SolrSearch and it worked fine. After I installed Search API (according to this page), when I replace 2 XML files, I get "400" Status: [doc=search_index-25] missing required field: entity_type. Please help. I really apreciate it.
Are you running the latest
Are you running the latest version of Search API module? Also, where are you getting the 400 error? In Drupal or Apache Solr.
Add new comment