Skip to content

Commit

Permalink
Merge pull request #831 from pulibrary/533-index-tasks
Browse files Browse the repository at this point in the history
Add more functionality to reindexing tasks
  • Loading branch information
eliotjordan committed Sep 15, 2020
2 parents 35c28fa + 973529a commit 7c3eb3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
10 changes: 0 additions & 10 deletions lib/tasks/dev.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ if Rails.env.development? || Rails.env.test?
require "factory_bot"

namespace :pomegranate do
desc 'Reindex a resource from a IIIF Manifest URL within an Exhibit'
task :reindex, %i[manifest exhibit] => [:environment] do |_t, args|
manifest = args[:manifest]
exhibit_slug = args[:exhibit]
exhibit = Spotlight::Exhibit.find_by(slug: exhibit_slug)
iiif_resource = IIIFResource.find_by(url: manifest, exhibit: exhibit)
iiif_resource.save_and_index_now
puts "Reindexed the document for #{manifest}"
end

desc 'Clear the SolrDocumentSidecar reference fields'
task :sidecar_clean_references, [:exhibit] => [:environment] do |_t, args|
exhibit_slug = args[:exhibit]
Expand Down
31 changes: 31 additions & 0 deletions lib/tasks/index.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,35 @@ namespace :reindex do
Spotlight::ReindexJob.perform_later(exhibit)
end
end

desc 'Index or reindex a resource from a IIIF Manifest URL within an Exhibit'
task :manifest, %i[manifest exhibit] => [:environment] do |_t, args|
manifest = args[:manifest]
exhibit_slug = args[:exhibit]
exhibit = Spotlight::Exhibit.find_by(slug: exhibit_slug)
iiif_resource = IIIFResource.find_or_initialize_by(url: manifest, exhibit: exhibit)
iiif_resource.save_and_index_now
puts "Reindexed the document for #{manifest}"
end

desc 'Reindex a resource from a noid and Exhibit'
task :noid, %i[noid exhibit] => [:environment] do |_t, args|
noid = args[:noid]
exhibit_slug = args[:exhibit]
config = CatalogController.blacklight_config
repo = FriendlyIdRepository.new(config)
exhibit = Spotlight::Exhibit.find_by(slug: exhibit_slug)
docs = repo.search(q: "access_identifier_ssim:#{noid}")["response"]["docs"]
resources = docs.map { |doc| Spotlight::Resource.find(doc["spotlight_resource_id_ssim"].first.split("/").last) }
iiif_resource = resources.find { |r| r.exhibit_id == exhibit.id }
iiif_resource.save_and_index_now
puts "Reindexed the document for #{noid}"
end
end

namespace :index do
desc 'Commit the index'
task commit: :environment do
Blacklight.default_index.connection.commit
end
end

0 comments on commit 7c3eb3a

Please sign in to comment.