Skip to content

Commit

Permalink
Rework FileSetIndexer and add text search
Browse files Browse the repository at this point in the history
This commit will enable `all_text_tsimv` and `is_page_of_ssim` to be set
on the FileSet.  By adding `all_text_tsimv` to Solr, the OCR can be now
searched through UV and any hits will be highlighted.  In addition, if a
parent work has any child works that have the OCR, those hits will also
be indicated in the left pane via a blue magnifying glass.
  • Loading branch information
kirkkwang committed Jan 26, 2023
1 parent ace2a26 commit 752fbb2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/indexers/concerns/iiif_print/file_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def generate_solr_document
super.tap do |solr_doc|
# only UV viewable images should have is_page_of, it is only used for iiif search
solr_doc['is_page_of_ssim'] = [ancestor_ids(object)] if object.mime_type&.match(/image/)
solr_doc['all_text_tsimv'] = object.extracted_text.content if object.try(:extracted_text).try(:content)&.present?
index_full_text(object, solr_doc)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def base_url
# return the first file set id
# @return [String]
def file_set_id
return document['id'] if document.file_set?

file_set_ids = document['file_set_ids_ssim']
raise "#{self.class}: NO FILE SET ID" if file_set_ids.blank?
file_set_ids.first
Expand Down
8 changes: 0 additions & 8 deletions lib/generators/iiif_print/blacklight_iiif_search_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ def adjust_catalog_controller_is_page_of_config
" object_relation_field: 'is_page_of_ssim',")
end

# Update the IiifSearchBuilder
def adjust_iiif_search_builder
marker = 'solr_parameters[:hl] = true'
inject_into_file 'app/models/iiif_search_builder.rb', after: marker do
"\n solr_parameters[:qf] = blacklight_config.iiif_search[:full_text_field]"
end
end

def inject_search_behavior
copy_file 'search_behavior.rb',
'app/models/concerns/blacklight_iiif_search/search_behavior.rb'
Expand Down
1 change: 1 addition & 0 deletions lib/iiif_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require "iiif_print/tiff_derivative_service"
require "iiif_print/metadata"
require "iiif_print/works_controller_behavior"
require "iiif_print/catalog_controller_decorator"

module IiifPrint
extend ActiveSupport::Autoload
Expand Down
26 changes: 26 additions & 0 deletions lib/iiif_print/catalog_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module IiifPrint
module CatalogControllerDecorator
# rubocop:disable Metrics/MethodLength
def iiif_search
_parent_response, @parent_document = fetch(params[:solr_document_id])
iiif_search = ::BlacklightIiifSearch::IiifSearch.new(iiif_search_params, iiif_search_config,
@parent_document)
@response, _document_list = search_results(iiif_search.solr_params)
iiif_search_response = ::BlacklightIiifSearch::IiifSearchResponse.new(@response,
@parent_document,
self)
json_results = iiif_search_response.annotation_list
json_results&.[]('resources')&.each do |result_hit|
next if result_hit['resource'].present?
result_hit['resource'] = {
"@type": "cnt:ContentAsText",
"chars": "Metadata match, see sidebar for details"
}
end

render json: json_results,
content_type: 'application/json'
end
end
# rubocop:enable Metrics/MethodLength
end
2 changes: 2 additions & 0 deletions lib/iiif_print/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Engine < ::Rails::Engine
Hyrax::ManifestBuilderService.prepend(IiifPrint::ManifestBuilderServiceBehavior)
Hyrax::WorksControllerBehavior.prepend(IiifPrint::WorksControllerBehaviorDecorator)
Hyrax::WorkShowPresenter.prepend(IiifPrint::WorkShowPresenterDecorator)
Hyrax::FileSetIndexer.prepend(IiifPrint::FileSetIndexer)
CatalogController.prepend(IiifPrint::CatalogControllerDecorator)

# Extending the presenter to the base url which includes the protocol.
# We need the base url to render the facet links and normalize the interface.
Expand Down

0 comments on commit 752fbb2

Please sign in to comment.