4

我正在关注这个在 Capistrano https://gist.github.com/doitian/1795439中添加 Sunspot Solr 的片段,它可以工作,但是当我运行 cap solr:reindex 时,它会显示一个问题(如预期的那样),询问我是否想要删除所有索引,所以我回答“是”,但终端似乎正在等待响应。

这是重新索引的代码:

  desc "reindex the whole database"
  task :reindex, :roles => :app do
    stop
    run "rm -rf #{shared_path}/solr/data"
    start
    run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} sunspot:solr:reindex" 
  end

这是消息:

  * executing "cd /home/user/rapps/app/current && bundle exec rake RAILS_ENV=production sunspot:solr:reindex"
    servers: ["9.9.9.9"]
    [9.9.9.9] executing command
 ** [out :: 9.9.9.9] *Note: the reindex task will remove your current indexes and start from scratch.
 ** [out :: 9.9.9.9] If you have a large dataset, reindexing can take a very long time, possibly weeks.
 ** [out :: 9.9.9.9] This is not encouraged if you have anywhere near or over 1 million rows.
 ** [out :: 9.9.9.9] Are you sure you want to drop your indexes and completely reindex? (y/n)
y

如何避免该消息?另外,我想用 Cron 运行这个 rake,那么我之前怎么能给出答案或设置默认配置?什么是重新索引的最佳/有效方法?

提前致谢。

4

3 回答 3

6

我最近遇到了这个问题,发现这是一个有用的解决方法:

yes | bundle exec rake sunspot:reindex
于 2013-07-06T14:53:08.877 回答
4

取请求现已在 sunspot gem 上合并。您应该可以rake sunspot:reindex[,,true]用来触发静音重新索引。

再次模因拯救地球

于 2013-04-13T00:44:09.393 回答
2

在查看了 sunspot_rails 源之后,目前没有办法强行绕过这条消息。请参阅此处定义的 rake 任务代码

已经提交了一个拉取请求(一个月前)(Pull request here),要求 rake 任务支持静默选项,但尚未合并。

我会:

  1. 分叉位于此处的 sunspot gem Repo并自己对 rake 任务进行更改(然后更改环境 Gemfile 以使用分叉的 gem)。
  2. 向 Capistrano 任务添加一个睡眠命令(大约 10 秒,比此命令出现应该花费的时间更长),然后为标准输入提供“y”
于 2013-03-28T19:34:24.373 回答