Want to learn more about search in Drupal 7? Then check out our online video course called “Build Powerful Search Pages with Views and Search API in Drupal 7“.
Running Search API and Apache Solr just got easier thanks to the latest release of the Search API Solr search module. This module allows you to use Solr as a server backend for Search API indexes. In the latest release (7.x-1.0-rc4) the module no longer has a dependency on the SolrPhpClient library.
In this tutorial I’ll show you how to setup a local development Solr server on Mac OS X 10.8.3.
Please note that this tutorial should only be used to setup a development server where you’re not worried about locking down Solr. If you want to setup Solr for a production site, then make sure you lock down the server so users can not get access to Solr.
Step 1: Check Java
First, check and make sure Java is installed. Open the Terminal app and enter java -version
, if the version is 1.6 you’re good to go.
Step 2: Download Search API Solr Module
Download and install the Search API Solr search module for Search API.
If you use Drush, run the following command:
$ drush dl search_api_solr
Step 3: Download Solr
Before we begin, download Solr (3.x) and extract the tar or zip file somewhere on your filesystem. Currently, only Solr 3.x is supported so don’t download the 4.x version.
Step 4: Configure Solr
Go to where you extracted Solr and duplicate the example
folder. Rename the duplicated folder drupal-search
. You can call the folder whatever you want just make it descriptive.
Go to the Search API Solr module and copy the files in the search_api_solr/solr-conf/3.x
folder into drupal-search/solr/conf
within Solr itself.
Step 5: Start Solr
Now we have everything setup it’s time to start Solr. We need to run Solr from the Terminal App, so open Terminal and go to the Solr directory.
Go into the drupal-search
folder and run java -jar start.jar
.
To see if Solr is working, go to http://localhost:8983/solr/admin/ and you should see the Solr administration page.
Step 6: Create Search API Server
The last and final step is to create a Solr Search API server for our index.
1. Go to Configuration -> “Search API” and click on “Add server”.
2. In the text field “Server name” enter “Solr server” and from the “Service class” drop-down list select “Solr service”.
3. Leave all the Solr settings as is and click on “Create server”.
4. When you create an index, make sure you select “Solr server” from the Server drop-down list.
If you want to learn how to use Search API please read “Intro To Search API (Part 1) – How To Create Search Pages” and “Intro To Search API (Part 2) – Faceted Search“.
If you have any questions, please leave a comment.
I wonder if normally shared hosting with cpanel or Direct Admin has usually Apache Solr installed? How to know whether a hosting is running on Apache Solr? Will it indicate in phpinfo.php ? Thanks.
Apache Solr runs separately to PHP. You can’t just view phpinfo.php and see if it’s installed.
Your shared hosting provider needs to offer it.
Hi! I’d like to say thank you for all of these tutorials, it really helped me. But in Drupal is it possible to use the data coming from Solr in Drupal so that I could display it in a search page?
Yes, look at the Apache Solr (https://drupal.org/project/apachesolr) module or Search API module (http://drupal.org/project/search_api). Both allow you to use Solr as a search engine.
I wrote a tutorial on how to create a search page using Search API, http://webwash.net/tutorials/intro-search-api-part-1-how-create-search-pages
Hi Ivan
Thank you for the tutorial
On Step 5: Start Solr
“Go into the drupal-search folder and run java -jar start.jar.”
Once I get solr running.
How do you exit it from the command line?
I’ve tried Crtl + C
This exit but switch’s off solr too
Many Thanks for your help
That’s how the command is meant to work. You should only run Jetty (Solr) this way on your local machine and just for testing.
Normally, I have multiple terminals open up just for this. Look at the link below on how to run Jetty in the background:
http://stackoverflow.com/questions/4287561/how-to-run-solr-jetty-in-background
Hi
I am debating whether to set up a local instance of Apache Solr – using your solution – or whether to go straight to a hosted solution, e.g. opensolr.com, to save any deployment issues. Ideally, I would like to develop locally first.
My question is, for a new comer to Apache Solr, is it straightforward to change from a local Apache Solr instance to a hosted solution? I have deployed local Drupal sites to hosting without issue, but including Apache Solr search is an unknown. Any advice would be appreciated.
“is it straightforward to change from a local Apache Solr instance to a hosted solution”
It depends. I’ve never used opensolr.com so I can’t comment. But when you’re ready to move to a hosted solution it should be as simple as copying over the Solr configuration.
Great post Ivan, thanks.
FWIW the instructions for 4.x are identical.
Great, thanks for testing on 4.x.