-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreindex.rake
47 lines (44 loc) · 1.29 KB
/
reindex.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
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