【发布时间】:2013-09-11 04:02:31
【问题描述】:
默认情况下,sunspot solr gem 向 solr 服务器发出索引命令,作为保存回调的一部分。这种行为在我的大多数应用程序中是可以接受的,但是在其中的某些部分(尤其是用于批量处理的 rake 任务中)我想在不与 solr 服务器进行任何交互的情况下保存我的模型实例。我如何做到这一点?
【问题讨论】:
标签: ruby-on-rails solr sunspot sunspot-rails sunspot-solr
默认情况下,sunspot solr gem 向 solr 服务器发出索引命令,作为保存回调的一部分。这种行为在我的大多数应用程序中是可以接受的,但是在其中的某些部分(尤其是用于批量处理的 rake 任务中)我想在不与 solr 服务器进行任何交互的情况下保存我的模型实例。我如何做到这一点?
【问题讨论】:
标签: ruby-on-rails solr sunspot sunspot-rails sunspot-solr
要禁用它,请将auto_commit_after_request: false 添加到您的sunspot.yml。
【讨论】:
根据docs,我认为您应该将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]
【讨论】: