ruby-on-railsmongodbsolrmongomappersunspot-rails

Solr Sunspot - Reindexing objects is not automatically running


i'm using Sunspot Solr for indexing and searching in our Ruby on Rails application with MangoDB database (Mongo mapper)

The searching works well, but objects aren't automatically indexed to Solr when i make changes on my database.

I tried manually index on a class itself:

Top.reindex Sunspot.commit

Or, I added on sunspot.yml : auto_commit_after_request: true I also autocommit with some interval on solrconfig.xml :

<autoCommit>
<maxDocs>10000</maxDocs>
<maxTime>15000</maxTime>
</autoCommit>

All this solutions failed to reindex automatically my objects, unless i reindex all objects with rake task :

bundle exec rake sunspot:reindex 

Any other solutions ?

Thanks a lot.


Solution

  • Sunspot is supposed to reindex by default if you're using ActiveRecord (check this).

    Problem here is that you're using Mongo, not AR. I found a gem that integrates sunspot and mongo mapper for this purposes. You might want to check it and see if it solves your problem on auto-indexing - gem is supposed to solve it (check this)

    If this doesn't work, you can try to doing some manual indexing on involved models, similar to the ActiveRecord hooks, for instance on a User model:

    after_save { |user| Sunspot.index!(user) }
    after_destroy { User.reindex; Sunspot.commit }