仅当可搜索字段发生变化时才建立太阳黑子索引
我们在最新的项目中使用太阳黑子进行搜索。我们还使用 devise 并按如下方式索引我们的用户模型:
searchable do
text :fname
text :lname
text :email
text :description
text :twitter_username
end
使用此设置,除非 solr 正在运行,否则用户甚至无法登录。这意味着在每次保存用户模型时,即使没有任何可搜索字段发生变化,也会与我们的 solr 服务器进行一些通信(重新索引?)。这是正确的吗?
我们还有许多其他模型正在按太阳黑子索引,这些模型具有经常更新的不可搜索字段。看起来太阳黑子正在为所有这些更新重新索引它们。
有没有办法将 sunspot 配置为仅在可搜索字段更改时与 solr 交互?
We are using sunspot for search in our latest project. We also use devise and are indexing our user model as follows:
searchable do
text :fname
text :lname
text :email
text :description
text :twitter_username
end
With this setup, a user cannot even log in unless solr is running. This implies that on every save of the User model, there is some communication to our solr server (reindexing?), even if none of the searchable fields have changed. Is this correct?
We also have lots of other models which are being indexed by sunspot which have non-searchable fields that are updated frequently. It appears as though sunspot is reindexing them on all of these updates.
Is there way to configure sunspot to only interface with solr when a searchable field changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您拥有最新版本的 sunspot gem。
每次模型更改时,太阳黑子都会重新索引。要调整此行为(请参阅可搜索选项):
可搜索:ignore_attribute_changes_of => [:平均评级,:永久链接] 做
文字:标题
结束
查看源代码:https://github.com/outoftime/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/searchable.rb
您的网站应该仍然可以工作,直到第一次请求 solr:
全文搜索请求
索引请求
您可能会在每次用户登录时对用户模型进行更新,因此会触发重新索引。
更多提示:
其实,花费大量时间的不是索引,而是commit命令;默认情况下,在每个 Web 请求结束时发出 commit 命令;这在生产环境中成本非常高。我建议您将政策更改为X 秒后自动提交;
如果您希望修补 sunspot 以便您的站点在 solr 服务器出现故障时可以正常工作,我建议您看一下这个 gem,它模拟了测试环境的服务器接口: sunspot_matchers
I'll assume you have the latest version of sunspot gem.
Sunspot reindexes each time the model has changed. To tweak this behaviour (see options for searchable):
searchable :ignore_attribute_changes_of => [ :average_rating, :permalink ] do
text :title
end
Take a look on the source code: https://github.com/outoftime/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/searchable.rb
Your site should still work until the first request to solr:
either a full text search request
either an indexing request
You are probably making an update on the user model each time a user logs in, therefore triggering a reindex.
More tips:
in fact, it's not the indexing that takes a lot of time, it's the commit command; the commit command is issued, by default, on the end of each web request ; This is very costly in a production env. I advice you to change the policy to autocommit after X seconds;
if you want that your want to patch sunspot so that you site should work in case of solr server failure, I advise you to take a look on this gem, that mocks server interface for the test env: sunspot_matchers