diff --git a/sunspot_rails/lib/sunspot/rails/tasks.rb b/sunspot_rails/lib/sunspot/rails/tasks.rb index 5203b6198..9e5e9f975 100644 --- a/sunspot_rails/lib/sunspot/rails/tasks.rb +++ b/sunspot_rails/lib/sunspot/rails/tasks.rb @@ -14,13 +14,17 @@ # $ rake sunspot:reindex[1000,Post] # reindex only the Post model in # # batchs of 1000 # $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model - task :reindex, [:batch_size, :models] => [:environment] do |t, args| - puts "*Note: the reindex task will remove your current indexes and start from scratch." - puts "If you have a large dataset, reindexing can take a very long time, possibly weeks." - puts "This is not encouraged if you have anywhere near or over 1 million rows." - puts "Are you sure you want to drop your indexes and completely reindex? (y/n)" - answer = STDIN.gets.chomp - return false if answer == "n" + # $ rake sunspot:reindex[,,true] # reindex silencing/skipping the boolean prompt + task :reindex, [:batch_size, :models, :silence] => [:environment] do |t, args| + args.with_defaults(:silence => false) + if args[:silence] == false + puts "*Note: the reindex task will remove your current indexes and start from scratch." + puts "If you have a large dataset, reindexing can take a very long time, possibly weeks." + puts "This is not encouraged if you have anywhere near or over 1 million rows." + puts "Are you sure you want to drop your indexes and completely reindex? (y/n)" + answer = STDIN.gets.chomp + return false unless answer.match(/^y/) + end # Retry once or gracefully fail for a 5xx error so we don't break reindexing Sunspot.session = Sunspot::SessionProxy::Retry5xxSessionProxy.new(Sunspot.session)