In ruby on rails , The go to option for most of the developers is solr by sunspot. https://github.com/sunspot/sunspot. They already do have an excellent readme and provide indepth instruction on using sunspot and in installing it in development environment. However, In production environment it is completely a different story.
For those of you using heroku. It is quite easy as you can just add websolr add on https://devcenter.heroku.com/articles/websolr and you should be good to go.
However, For those who are hosting the rails app in their own VPS and server boxes you will need to dig a bit deeper. As you probably now that as ruby developers we are overwhelmed when dealing with JVM and XML configurations.
So i’ll try to make it a bit simpler.
- ssh into your machine
(add following PPA for java 7 as java is a prerequisite . )
sudo apt-add-repository -y ppa:webupd8team/java
sudo apt-get update
sudo echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
sudo apt-get install -y oracle-java7-installer
Now are are ready to install Solr
I am going with apache solr version of 5.4.0 . You can substitute proper versions in the commands below.
tar xzf solr-5.4.0.tgz solr-5.4.0/bin/install_solr_service.sh --strip-components=2
sudo ./install_solr_service.sh solr-5.4.0.tgz
Solr process 9073 running on port 8983
"version":"5.2.1 1684708 - shalin - 2015-06-10 23:20:13",
"uptime":"0 days, 0 hours, 36 minutes, 13 seconds",
"memory":"49.7 MB (%10.1) of 490.7 MB"}
Now we can create a collection core for our rails application
su - solr -c "/opt/solr/bin/solr create -c solr_sunspot_my_core_example -n data_driven_schema_configs"
This would create a collection that is empty at /var/solr/data/solr_sunspot_my_core_example with a config/solrconfig.xml file.
However, for our rails application to be able to make user of the solr configurations we would need to copy the configurations from sunspot .
so we can head over to
and remove existing solrconfig.xml file there
get new copies of the solrconfig.xml and solr by executing following
Restart the solr service
service solr restart
head to your rails application and edit config/sunspot.yml now to reflect our configuration paths
That should be it.
You can reindex with following now in your rails application folder
Your search should be working now.