Sunspot Index Only When Searchable Fields Change

We are using sunspot for search in our latest project. We also use devise and are indexing our user model as follows:

searchable do
  text :fname
  text :lname
  text :email
  text :description
  text :twitter_username

With this setup, a user cannot even log in unless solr is running. This implies that on every save of the User model, there is some communication to our solr server (reindexing?), even if none of the searchable fields have changed. Is this correct?

We also have lots of other models which are being indexed by sunspot which have non-searchable fields that are updated frequently. It appears as though sunspot is reindexing them on all of these updates.

Is there way to configure sunspot to only interface with solr when a searchable field changes?


I'll assume you have the latest version of sunspot gem.

  1. Sunspot reindexes each time the model has changed. To tweak this behaviour (see options for searchable):

    searchable :ignore_attribute_changes_of => [ :average_rating, :permalink ] do text :title end

    Take a look on the source code:

  2. Your site should still work until the first request to solr:

    • either a full text search request

    • either an indexing request

    You are probably making an update on the user model each time a user logs in, therefore triggering a reindex.

More tips:

  • in fact, it's not the indexing that takes a lot of time, it's the commit command; the commit command is issued, by default, on the end of each web request ; This is very costly in a production env. I advice you to change the policy to autocommit after X seconds;

  • if you want that your want to patch sunspot so that you site should work in case of solr server failure, I advise you to take a look on this gem, that mocks server interface for the test env: sunspot_matchers

Need Your Help

How to modify ng-model within Angular $parsers pipeline

angularjs parsing angularjs-directive angular-ngmodel

I have a single box.width ng-model value within a form, intending to store the box's width in inches. I'd like users to be able to see the width in "ft" and "in", though. For the most part, I have it

UITabBar customisation not working as expected

objective-c ios uitabbar uiappearance

I have a three tab UITabBar in which the background of each tab is set, along with the background of the tabbar itself, as seen in the first image below. Each UITabBarItem has its FinishedSelectedI...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.