Last active
July 24, 2020 04:10
-
-
Save lassebunk/107b4406aacfac85e42b to your computer and use it in GitHub Desktop.
Revisions
-
lassebunk revised this gist
Jul 17, 2014 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ # This task can be used reindex Solr without dropping your index first. # This is ideal for production environments where a live, working index is critical. # # Put this in lib/tasks/sunspot_tasks.rake namespace :sunspot do task reindex_gracefully: :environment do -
lassebunk created this gist
Jul 17, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # This task can be used to not drop your Solr index before reindexing it. namespace :sunspot do task reindex_gracefully: :environment do Dir.glob(Rails.root.join('app/models/**/*.rb')).each { |path| require path } sunspot_models = Sunspot.searchable index_options = { :batch_commit => false } begin require 'progress_bar' total_documents = sunspot_models.map { | m | m.count }.sum index_options[:progress_bar] = ProgressBar.new(total_documents) rescue LoadError => e $stdout.puts "Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile" rescue Exception => e $stderr.puts "Error using progress bar: #{e.message}" end sunspot_models.each do |model| model.solr_index index_options end end end