Skip to content

Commit

Permalink
Reindex SingleDate
Browse files Browse the repository at this point in the history
Rake task to re-indexing SingleDate Sorl documents.

Note ```Error Couldn't find ActiveFedora::Base with 'id'=xxxxx while indexing xxxxx results```
is result of Solr index data beeing ahead of Fedora data. Issue with local dev env.

The error must not occur on production system.
  • Loading branch information
paluchas committed Jun 20, 2021
1 parent 1ea1641 commit 9c14a18
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/tasks/index.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9c14a18

Please sign in to comment.