By default, the sunspot solr gem issues an index command to the solr server as part of the save callback. This behavior is acceptable in most of my app, but there are some parts of it (especially those in rake tasks for bulk processing) where I want to save instances of my model without any interaction whatsoever with the solr server. How do I achieve this?

有帮助吗?

解决方案

According to the docs I think you should add auto_index: false to your searchable block, i.e.:

class Foo < ActiveRecord::Base
  searchable auto_index: false do
    # your search fields here
  end
end

Then you can use the following methods to manually reindex records:

# On a class itself
Person.reindex
Sunspot.commit # or commit(true) for a soft commit (Solr4)

# On mixed objects
Sunspot.index [post1, item2]
Sunspot.index person3
Sunspot.commit # or commit(true) for a soft commit (Solr4)

# With autocommit
Sunspot.index! [post1, item2, person3]

其他提示

To disable it add auto_commit_after_request: false to your sunspot.yml.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top