4

默认情况下,sunspot solr gem 向 solr 服务器发出索引命令,作为保存回调的一部分。这种行为在我的大多数应用程序中是可以接受的,但是其中的某些部分(尤其是用于批量处理的 rake 任务中的那些)我想在不与 solr 服务器进行任何交互的情况下保存我的模型实例。我如何实现这一目标?

4

2 回答 2

5

根据文档,我认为您应该添加auto_index: false到可搜索块中,即:

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

然后您可以使用以下方法手动重新索引记录:

# 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]
于 2013-09-11T08:42:11.177 回答
-1

要禁用它,请添加auto_commit_after_request: false到您的sunspot.yml.

于 2013-09-09T12:30:22.613 回答