Solr is an awesome app built on top of Lucene for fulltext search. However, setting it up can be a pain if you don’t find the right guide, or if you miss some small detail. So, here is my attempt to document the process of setting up solr in development and production using a rails app as an example.
Solr and Lucene are java apps, so you need java to get this stuff working, I installed sun-jdk just to play it safe, as far as I know it works well even with openjdk.
Steps to setup solr on production
- Install Sun JDK:
1 |
|
Download and setup tomcat: you’ll need to setup tomcat version 6.0 for your production server. Download the latest V6 tomcat files from http://tomcat.apache.org/download-60.cgi. Now, extract them into
~/apps
.Download or build the solr war files and copy them to
/apps/solr
. You can find the links at: http://lucene.apache.org/solr/ or http://www.apache.org/dyn/closer.cgi/lucene/solr/. The war file is usually in a folder calleddist
and has a filename likeapache-solr-3.4.0.war
Create a file ~/apps/tomcat/conf/Catalina/localhost/solr-appname.xml with the following content
1 |
|
Steps till this point are the same for any kind of solr installation, be it for a rails or any other app.
- I use the sunspot_rails gem in my rails application, when using this, you can run
rails g sunspot_rails:install
to create aconfig/sunspot.yml
file. Once you have the config file, change the production config values to point to the right port and path, e.g:
1 |
|
- Run the
bundle exec rake sunspot:solr:start
command once, on the development machine, to generate the solr configuration files. And push this code to the production server.
That’s all. Setting solr is not very straightforward, but once you have it set up, it’s very easy to setup additional apps with the same solr server.
On a development machine, all you need to get solr working is: install java (check step 1) and setup sunspot (check step 5), and start the solr server with bundle exec rake sunspot:solr:start
###Resources###
- https://help.ubuntu.com/community/Java
- http://wiki.apache.org/solr/SolrInstall
- http://www.tc.umn.edu/~brams006/solr_ubuntu.html
- http://railscasts.com/episodes/278-search-with-sunspot
- https://github.com/outoftime/sunspot
- https://github.com/sunspot/sunspot/wiki