Sha256: b4819662cc0796a5cafa17a8ec2a7cab06b66ae9d449ba75d07ba82fbcc580d4
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
module IiifPrint module IiifSearchResponseDecorator # Enable the user to search for child metadata in the parent's UV # @see https://github.com/scientist-softserv/louisville-hyku/commit/67467e5cf9fdb755f54419f17d3c24c87032d0af def annotation_list json_results = super # Check and process invalid hit if json_results&.[]('resources') remove_invalid_hit(json_results) add_metadata_match(json_results) end json_results end def remove_invalid_hit(json_results) resources = json_results['resources'] invalid_hit = resources.detect { |resource| resource["on"].include?(IiifPrint::BlacklightIiifSearch::AnnotationDecorator::INVALID_MATCH_TEXT) } return unless invalid_hit # Delete invalid hit from resources, remove first hit (which is from the invalid hit), decrement total within resources.delete(invalid_hit) json_results['hits'].shift json_results['within']['total'] -= 1 end def add_metadata_match(json_results) json_results['resources'].each do |result_hit| next if result_hit['resource'].present? # Add resource details if not present result_hit['resource'] = { "@type": "cnt:ContentAsText", "chars": "Metadata match, see sidebar for details" } end end end end
Version data entries
3 entries across 3 versions & 1 rubygems