1

I'm using sunspot for handling solr in my spree commerce application. I've defined it for my product model:

Spree::Product.class_eval do
  searchable :auto_index => true, :auto_remove => true do
  ...
  end
end

At index time, everything gets into Solr and works fine. But when I try to edit a product, the changes aren't saved to Solr. For example, adding a unique word like testtest to the title of a product, and then search for that keyword returns nothing. When I reindex the whole database, it works.

Inside the sunspot.yml I'm using the auto_commit_after_request: true option.

I tailed the log/sunspot-solr-development.log where every search gets logged. But it seems that editing a product doesn't make any call to Solr. I thought that using the :auto_index => true option would trigger the saves to the database (in production I'm going to use the autoCommit feature from Solr).

So, I'm a little bit stuck. I have no idea, where sunspot hooks into the save blocks, or is it RSolr in the background? Maybe someone can help me to fix this problem.

EDIT

I just saw, that when using Sunspot, the model class gets some methods like index and index!. The strange thing is, that inside the console rails c this methods are listed when calling Spree::Product.first.methods. But when I hook into the update method from the products controller, this methods aren't there. So maybe I have some problems during initializing the sunspot stuff.

FYI: The code from above (Spree::Product.class_eval do) is inside an initializer under config/initializers/sunspot/sunspot_product.rb.

23tux
  • 14,104
  • 15
  • 88
  • 187

2 Answers2

0

You should use solr_index and solr_index! methods from the controller.

solr_index api documentation

Mark Ellul
  • 1,906
  • 3
  • 26
  • 37
0

After years has been passed I like to provide the another option for this question.

You can edit the solrconfig.xml and set the

autoSoftCommit

to any milliseconds that you want to index. You might not want to reinvent the whole wheel by indexing the records by yourself.

Also take a look at this reference When should we apply Hard commit and Soft commit in SOLR?

Community
  • 1
  • 1
zawhtut
  • 8,335
  • 5
  • 52
  • 76