-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds MyReindex to assist with SOLR upgrade.
- Loading branch information
Thomas Scherz
committed
Sep 11, 2024
1 parent
edc4342
commit e4338b9
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace :reindex do | ||
desc "Reindex specified work, e.g., rake myreindex:reindex_by_id['c821gj76b']" | ||
task :reindex_by_id, [:id] => :environment do |_, args| | ||
object = find_or_warn(args[:id]) || next | ||
|
||
if object.id.blank? | ||
$stderr.puts "No such work exists for id: #{object.id}" | ||
next | ||
else | ||
ActiveFedora::Base.find(object.id).update_index | ||
puts "Reindexed work id #{object.id}" | ||
end | ||
end | ||
|
||
desc "Reindex collections" | ||
task reindex_collections: :environment do | ||
count = 0 | ||
Collection.all.each do |object| | ||
if object.id.blank? | ||
$stderr.puts "No such work exists for id: #{object.id}" | ||
next | ||
else | ||
ActiveFedora::Base.find(object.id).update_index | ||
count +=1 | ||
end | ||
end | ||
puts "Reindexed works for #{count} objects" | ||
end | ||
|
||
desc "Reindex all objects" | ||
task :reindex_works => :environment do | ||
count = 0 | ||
[Image, Document, ExternalObject, MedSym, Review].each do |model_class| | ||
model_class.all.each do |object| | ||
if object.id.blank? | ||
$stderr.puts "No such work exists for id: #{object.id}" | ||
next | ||
else | ||
ActiveFedora::Base.find(object.id).update_index | ||
count += 1 | ||
end | ||
end | ||
end | ||
puts "Reindexed works for #{count} objects" | ||
end | ||
|
||
|
||
end | ||
|