Setup sunspot solr with rails in production environment
Asked Answered
I

2

28

I have tried various links but I can't seem to find a good resource on creating a running solr instance that works with rails in production.

I understand that you have to setup the solr server for production. I have tried the setup of solr with tomcat but I cant seem to link it to the rails app.

Is there any good resource out there that I could use?

Thanks

Indefinable answered 8/2, 2011 at 19:21 Comment(0)
A
7

This blog may solve your question:

Install Solr 4.4 with Jetty in CentOS, and set up Solr server to work with Sunspot Gem. ( http://blogs.pigrider.com/blogs/26 )

Below are some parts from the blog: ......

8) Copy this configuration file schema.yml from your Rails application to the home directory of the running Solr 4.4 instance. It will overrider the Solr example configuration file there, and it will set up Solr 4.4 server to work with Sunspot Gem. cp /RailsApplicationPath/Solr/conf/schema.yml /opt/solr/solr/collection1/conf/.

The home directory of the running Solr 4.4 instance is /opt/solr/solr/collection1/. You can find this information from Solr admin page http:// l o c a l h o s t :8983/solr/admin

9) Add version field into the configuration file schema.yml to satisfy Solr 4.4 initialization requirement. Actually, two lines of code need to be added into the file. They are:

<field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>

<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>

The configuration file schema.yml eventually will look like:

<schema name="sunspot" version="1.0">
  <types>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <!-- *** Other Sunspot fieldType Definitions *** -->
  </types>

  <fields>
    <field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
    <!-- *** Other Sunspot field Definitions *** -->
  </fields>

  <!-- *** Other Sunspot Configurations *** -->
</schema>

......

Aroma answered 8/9, 2013 at 18:29 Comment(0)
I
42

The Sunspot gem includes the sunspot-solr binary. The simplest setup would be just to run sunspot-solr start. Depending on how your application is deployed, you might also include a task in your Capistrano deploy that uses Sunspot's provided rake task to start a Solr server. Namely, rake sunspot:solr:start RAILS_ENV=production.

Getting more in-depth from that could involve: installing Tomcat as a standalone service, started and stopped with its own init script (or Upstart config), ideally monitored by monit or god; downloading and deploying solr.war within Tomcat, and configuring the solr.xml to refer to a convenient location on disk for your index data, solrconfig.xml and schema.xml to be stored.

The Solr wiki also includes a page on installing Solr with Tomcat and other servlet containers.

In either of the above self-hosted options, there's an important point to keep in mind with Sunspot: disable its automatic commits, and rely on Solr's own autoCommit settings in solrconfig.xml. You can disable those commits by setting auto_commit_after_request: false in your config/sunspot.yml.

Finally, if you're more interested in just outsourcing all of this, there's also my own humble hosted Solr service over at http://websolr.com/ — we can have you up and running in just a few clicks.

Ingle answered 8/2, 2011 at 23:57 Comment(8)
I finally managed to run solr with tomcat in ubuntu 10.04 server. The last remaining thing is how do I connect this to my rails application?Indefinable
@Nick, could you provide more info on why we should set auto_commit_after_request to false in this scenario? This is the only place I've seen that mentioned.Birdseed
Commits are expensive, and block other writes. Issuing a commit after every request is fine for development, and small sites in production, but will become a burden on all your updates to Solr as your write traffic grows. You're right that this is probably not very prominently documented right now.Ingle
At Websolr, we address this on the server side and completely ignore incoming commits in favor of an autoCommit setting.Ingle
auto_commit_after_request: false applies for Sunspot managed indexing. If you have custom indexing remove ! from <AR>.index! and just use <AR>.index. We have Solr server run 100% CPU with index!. Removing ! and auto-commit every 10 seconds got it down to 3%.Versed
@NickZadrozny May I ask, if I use solr autocommit instead of Sunspot default, is there still a reason to set up a standalone solr server?Lavellelaven
@lulalala: sorry, I'm not sure I understand your question…Ingle
@NickZadrozny I want to ask if there is any other reason to set up a standalone solr server, beside Sunspot's commit policy which degrades performance.Lavellelaven
A
7

This blog may solve your question:

Install Solr 4.4 with Jetty in CentOS, and set up Solr server to work with Sunspot Gem. ( http://blogs.pigrider.com/blogs/26 )

Below are some parts from the blog: ......

8) Copy this configuration file schema.yml from your Rails application to the home directory of the running Solr 4.4 instance. It will overrider the Solr example configuration file there, and it will set up Solr 4.4 server to work with Sunspot Gem. cp /RailsApplicationPath/Solr/conf/schema.yml /opt/solr/solr/collection1/conf/.

The home directory of the running Solr 4.4 instance is /opt/solr/solr/collection1/. You can find this information from Solr admin page http:// l o c a l h o s t :8983/solr/admin

9) Add version field into the configuration file schema.yml to satisfy Solr 4.4 initialization requirement. Actually, two lines of code need to be added into the file. They are:

<field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>

<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>

The configuration file schema.yml eventually will look like:

<schema name="sunspot" version="1.0">
  <types>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <!-- *** Other Sunspot fieldType Definitions *** -->
  </types>

  <fields>
    <field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
    <!-- *** Other Sunspot field Definitions *** -->
  </fields>

  <!-- *** Other Sunspot Configurations *** -->
</schema>

......

Aroma answered 8/9, 2013 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.