保存后 sunspot_rails 不会重新索引模型 [英] sunspot_rails not re-indexing model after save

查看:58
本文介绍了保存后 sunspot_rails 不会重新索引模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型,它部署了一个更新其某些属性的延迟作业.该模型被声明为可搜索"...

I have a model which deploys a delayed job that updates some of its attributes. The model is declared "searchable"...

searchable do
  text :content, :stored => true  
end

...我认为保存后会重新索引.在测试中,情况似乎并非如此.如果我运行:rake sunspot:reindex,那么一切都按预期进行.什么可能导致此问题?

... which I thought would re-index after a save. On testing, this doesn't seem to be the case. If I run: rake sunspot:reindex, then everything works as expected. What could be causing this issue?

推荐答案

正如 Jason 所提到的,您可以调用 Sunspot.commit_if_dirty 从您的客户端发出提交.

As mentioned by Jason, you can call Sunspot.commit_if_dirty to issue a commit from your client.

从服务器配置方面来看,另一种方法是在您的 solrconfig.xml 中设置 autoCommit 属性,以便在对索引进行更改时自动发出提交.对于大多数网站来说,maxTime 为 60000 毫秒(一分钟)就足够了.

From the server configuration side, another approach would be to set the autoCommit property in your solrconfig.xml to automatically issue commits when there have been changes made to your index. A maxTime of 60000 ms (one minute) should suffice for most sites.

在生产应用程序中使用 autoCommit 可能是更明智的选择,因为大量提交很容易影响 Solr 服务器的性能.事实上,当您的网站开始获得大量更新时,Sunspot 最好禁用auto_commit_after_request 选项.

Using autoCommit is probably the wiser choice in production applications, where a high volume of commits can easily impact your Solr server's performance. In fact, it's a good practice with Sunspot to disable its auto_commit_after_request option when your site starts getting a decent amount of updates.

最后,autoCommit 的优势在于能够设置它并忘记它.

Lastly, autoCommit has the advantage of being able to set it and forget it.

Websolr 中,我们的默认设置是忽略客户端发出的提交以支持 autoCommit.

At Websolr, our default is to ignore client-issued commits in favor of autoCommit.

这篇关于保存后 sunspot_rails 不会重新索引模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆