在数据库重建期间禁用 Solr
我正在开发一个涉及 solr sunspot gem 的 Rails 项目。我保留了默认行为以自动更新模型保存上的索引,但我想知道是否有一种方法可以在批量创建对象时(例如在 rake db:seed 过程中)暂时禁用索引。当使用种子命令时,我希望它会添加所有对象,然后执行一次大型重新索引调用来更新整个表。有什么想法吗?
谢谢!
I am working on a rails project that involves the solr sunspot gem. I left the default behavior to auto update the index on model saves, but I was wondering if there was a way to temporarily disable the indexing when mass creating objects, such as during a rake db:seed process. When using the seed command I was hoping it would add all of the objects and then perform one big reindex call to update the entire table. Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 Sunspot 的会话设置为 StubSessionProxy。
You could set Sunspot's session to a StubSessionProxy.
还有这个。
基本上,您应该能够将其添加到 sunspot.yml 中:
如果您直接在数据库上运行某些任务或查询,这非常有用。但是,如果您使用此设置运行应用程序,并且代码中的任何位置都有类似以下内容:
那么您将遇到如下错误:
There's also this.
Basically, you should be able to add this to sunspot.yml:
This works great if you're running some tasks or queries directly on the DB. However, if you are running your app with this setting, and anywhere in your code you have something like:
Then you'll hit an error like this: