sunspot_rails 保存后不重新索引模型

发布于 2024-09-17 07:13:53 字数 229 浏览 6 评论 0原文

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

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

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

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

... 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

要走就滚别墨迹 2024-09-24 07:13:53

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

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

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

最后,autoCommit 的优点是能够设置它并忘记它。

Websolr 中,我们的默认设置是忽略客户端发出的提交,而采用 autoCommit

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

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.

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.

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

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

呢古 2024-09-24 07:13:53

该索引仅反映调用 Sunspot.commit 后的更改。当您运行rake sunspot:reindex时,这种情况会自动发生。

Sunspot 的 Rails 插件还有一个 auto_commit_after_request 配置选项,它将在每次请求后调用 Sunspot.commit_if_dirty 但这不会由后台进程触发。

您最好的选择是在延迟工作的最后一件事之后调用 Sunspot.commit_if_dirty

The index will only reflect changes after Sunspot.commit is called. This happens automatically when you run rake sunspot:reindex.

Sunspot's Rails plugin also has a auto_commit_after_request config option which will call Sunspot.commit_if_dirty after every request but this will not be triggered by your background processes.

Your best bet is to call Sunspot.commit_if_dirty after as the last thing in your delayed job.

香草可樂 2024-09-24 07:13:53

我遇到了和你完全相同的问题 - 当我测试我的搜索功能时,sunspot 永远不会向 solr 发出提交。如果我手动调用 Sunspot.commit 一切正常。我摆弄了 auto_commit_after_request ,但默认情况下这是正确的,所以它不应该产生不同。

因此,经过更多调查后,我发现 Sunspot 不会自动发出提交,除非在 Web 请求的上下文中进行更改。如果您要对测试或后台作业进行更改,则必须手动调用 Sunspot.commit。

I had the exact same problem as you - when I was testing my search functionality sunspot would never issue a commit to solr. If I manually call Sunspot.commit everything works. I fiddled around with auto_commit_after_request, but this is true by default so it shouldn't make a different.

So after some more investigation I found that Sunspot won't issue a commit automatically unless the change is made in the context of a web request. If you're doing a change from a test or a background job you have to call Sunspot.commit manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文