Skip to content

Commit 8ebb3ff

Browse files
author
Thomas Scherz
committedSep 11, 2024·
Adds MyReindex to assist with SOLR upgrade.
1 parent edc4342 commit 8ebb3ff

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
 

‎lib/tasks/reindex.rake

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
namespace :reindex do
3+
desc "Reindex specified work, e.g., rake myreindex:reindex_by_id['c821gj76b']"
4+
task :reindex_by_id, [:id] => :environment do |_, args|
5+
object = find_or_warn(args[:id]) || next
6+
7+
if object.id.blank?
8+
$stderr.puts "No such work exists for id: #{object.id}"
9+
next
10+
else
11+
ActiveFedora::Base.find(object.id).update_index
12+
puts "Reindexed work id #{object.id}"
13+
end
14+
end
15+
16+
desc "Reindex collections"
17+
task reindex_collections: :environment do
18+
count = 0
19+
Collection.all.each do |object|
20+
if object.id.blank?
21+
$stderr.puts "No such work exists for id: #{object.id}"
22+
next
23+
else
24+
ActiveFedora::Base.find(object.id).update_index
25+
count += 1
26+
end
27+
end
28+
puts "Reindexed works for #{count} objects"
29+
end
30+
31+
desc "Reindex all objects"
32+
task reindex_works: :environment do
33+
count = 0
34+
[Image, Document, ExternalObject, MedSym, Review].each do |model_class|
35+
model_class.all.each do |object|
36+
if object.id.blank?
37+
$stderr.puts "No such work exists for id: #{object.id}"
38+
next
39+
else
40+
ActiveFedora::Base.find(object.id).update_index
41+
count += 1
42+
end
43+
end
44+
end
45+
puts "Reindexed works for #{count} objects"
46+
end
47+
end

0 commit comments

Comments
 (0)
Please sign in to comment.