Class: BlacklightIiifSearch::IiifSearchResponse
- Inherits:
-
Object
- Object
- BlacklightIiifSearch::IiifSearchResponse
- Includes:
- Ignored
- Defined in:
- app/models/blacklight_iiif_search/iiif_search_response.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#iiif_config ⇒ Object
readonly
Returns the value of attribute iiif_config.
-
#solr_response ⇒ Object
readonly
Returns the value of attribute solr_response.
Instance Method Summary collapse
-
#annotation_list ⇒ IIIF::OrderedHash
constructs the IIIF::Presentation::AnnotationList.
-
#clean_params ⇒ ActionController::Parameters
remove ignored or irrelevant params from the params hash.
-
#initialize(solr_response, parent_document, controller) ⇒ IiifSearchResponse
constructor
A new instance of IiifSearchResponse.
-
#paged_url(page_index) ⇒ String
create a URL for the previous/next page of results.
-
#resources ⇒ Array
Return an array of IiifSearchAnnotation objects.
- #within ⇒ IIIF::Presentation::Layer
Methods included from Ignored
Constructor Details
#initialize(solr_response, parent_document, controller) ⇒ IiifSearchResponse
Returns a new instance of IiifSearchResponse.
14 15 16 17 18 19 20 21 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 14 def initialize(solr_response, parent_document, controller) @solr_response = solr_response @parent_document = parent_document @controller = controller @iiif_config = controller.iiif_search_config @resources = [] @hits = [] end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 8 def controller @controller end |
#iiif_config ⇒ Object (readonly)
Returns the value of attribute iiif_config.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 8 def iiif_config @iiif_config end |
#solr_response ⇒ Object (readonly)
Returns the value of attribute solr_response.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 8 def solr_response @solr_response end |
Instance Method Details
#annotation_list ⇒ IIIF::OrderedHash
constructs the IIIF::Presentation::AnnotationList
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 26 def annotation_list list_id = controller.request.original_url anno_list = IIIF::Presentation::AnnotationList.new('@id' => list_id) anno_list['@context'] = %w[ http://iiif.io/api/presentation/2/context.json http://iiif.io/api/search/1/context.json ] anno_list['resources'] = resources anno_list['hits'] = @hits anno_list['within'] = within anno_list['prev'] = paged_url(solr_response.prev_page) if solr_response.prev_page anno_list['next'] = paged_url(solr_response.next_page) if solr_response.next_page anno_list['startIndex'] = 0 unless solr_response.total_pages > 1 anno_list.to_ordered_hash(force: true, include_context: false) end |
#clean_params ⇒ ActionController::Parameters
remove ignored or irrelevant params from the params hash
100 101 102 103 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 100 def clean_params remove = ignored.map(&:to_sym) controller.iiif_search_params.except(*%i[page solr_document_id] + remove) end |
#paged_url(page_index) ⇒ String
create a URL for the previous/next page of results
93 94 95 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 93 def paged_url(page_index) controller.solr_document_iiif_search_url(clean_params.merge(page: page_index)) end |
#resources ⇒ Array
Return an array of IiifSearchAnnotation objects
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 45 def resources @total = 0 solr_response['highlighting'].each do |id, hl_hash| hit = { '@type': 'search:Hit', 'annotations': [] } document = solr_response.documents.find { |v| v[:id] == id } if hl_hash.empty? @total += 1 annotation = IiifSearchAnnotation.new(document, solr_response.params['q'], 0, nil, controller, @parent_document) @resources << annotation.as_hash hit[:annotations] << annotation.annotation_id else hl_hash.each_value do |hl_array| hl_array.each_with_index do |hl, hl_index| @total += 1 annotation = IiifSearchAnnotation.new(document, solr_response.params['q'], hl_index, hl, controller, @parent_document) @resources << annotation.as_hash hit[:annotations] << annotation.annotation_id end end end @hits << hit end @resources end |
#within ⇒ IIIF::Presentation::Layer
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/blacklight_iiif_search/iiif_search_response.rb', line 78 def within within_hash = IIIF::Presentation::Layer.new within_hash['ignored'] = ignored if solr_response.total_pages > 1 within_hash['first'] = paged_url(1) within_hash['last'] = paged_url(solr_response.total_pages) else within_hash['total'] = @total end within_hash end |