Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e4338b9

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

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
 

‎lib/tasks/reindex.rake

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

0 commit comments

Comments
 (0)
Please sign in to comment.