Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reindex Sunspot Solr in Capistrano

I'm following this snippet for adding Sunspot Solr in Capistrano https://gist.github.com/doitian/1795439 and it works, but when I run cap solr:reindex it shows a question (as expected) asking if I want to drop all indexes, so I answer with "yes" but the terminal seems to be waiting for a response.

This is the code for the 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

This is the message:

  * 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

How can avoid that message? Also, I will like to run this rake with Cron so how could I previously give the answer or set a default configuration? And what is the best/efficient way to reindex?

Thanks in advance.

like image 581
pablomarti Avatar asked Dec 16 '22 12:12

pablomarti


1 Answers

I ran into this problem recently and found this to be a useful workaround:

yes | bundle exec rake sunspot:reindex
like image 62
Eric Hayes Avatar answered Dec 29 '22 06:12

Eric Hayes