diff --git a/lib/tasks/index.rake b/lib/tasks/index.rake index 6255f92..9501cee 100644 --- a/lib/tasks/index.rake +++ b/lib/tasks/index.rake @@ -47,4 +47,34 @@ namespace :index do end end end + + # bundle exec rake index:all_single_dates + desc "re-index all single dates to Solr" + task all_single_dates: :environment do + # Start timer + starting = Process.clock_gettime(Process::CLOCK_MONOTONIC) + # Find all places + solr = SolrQuery.new + query = 'has_model_ssim:SingleDate' + dates_response = solr.solr_query(query, 'id,date_tesim', rows=2147483647) + + total = dates_response['response']['numFound'].to_i + index = 1 + dates_response['response']['docs'].map do |date| + begin + date_id = date['id'] + date_label = date['date_tesim'][0] unless date['date_tesim'].blank? + print "indexing #{index} / #{total}: #{date_id} #{date_label} \n" + index += 1 + ActiveFedora::Base.find(date_id).update_index + rescue => e + print "Error #{e} while indexing #{date_id} \n" + end + end + # Stop timer + ending = Process.clock_gettime(Process::CLOCK_MONOTONIC) + seconds = ending - starting + hours = seconds/3600 + print "Total running time: #{hours}h \n" + end end