Class: BlacklightIiifSearch::IiifSuggestResponse
- Inherits:
-
Object
- Object
- BlacklightIiifSearch::IiifSuggestResponse
- Includes:
- Ignored
- Defined in:
- app/models/blacklight_iiif_search/iiif_suggest_response.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#document_id ⇒ Object
readonly
Returns the value of attribute document_id.
-
#iiif_config ⇒ Object
readonly
Returns the value of attribute iiif_config.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#solr_response ⇒ Object
readonly
Returns the value of attribute solr_response.
Instance Method Summary collapse
-
#iiif_search_url(term) ⇒ String
Create a URL corresponding to a IIIF Content Search request for the term.
-
#initialize(solr_response, params, controller) ⇒ IiifSuggestResponse
constructor
A new instance of IiifSuggestResponse.
-
#term_list ⇒ IIIF::OrderedHash
Constructs the termList as IIIF::Presentation::Resource.
-
#terms ⇒ Array
Turn solr_response into array of hashes ‘try’ chain pattern copied from Blacklight::Suggest::Response#suggestions.
Methods included from Ignored
Constructor Details
#initialize(solr_response, params, controller) ⇒ IiifSuggestResponse
Returns a new instance of IiifSuggestResponse.
14 15 16 17 18 19 20 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 14 def initialize(solr_response, params, controller) @solr_response = solr_response @query = params[:q] @document_id = params[:solr_document_id] @controller = controller @iiif_config = controller.iiif_search_config end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 8 def controller @controller end |
#document_id ⇒ Object (readonly)
Returns the value of attribute document_id.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 8 def document_id @document_id end |
#iiif_config ⇒ Object (readonly)
Returns the value of attribute iiif_config.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 8 def iiif_config @iiif_config end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 8 def query @query end |
#solr_response ⇒ Object (readonly)
Returns the value of attribute solr_response.
8 9 10 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 8 def solr_response @solr_response end |
Instance Method Details
#iiif_search_url(term) ⇒ String
Create a URL corresponding to a IIIF Content Search request for the term
54 55 56 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 54 def iiif_search_url(term) controller.solr_document_iiif_search_url(document_id, q: term) end |
#term_list ⇒ IIIF::OrderedHash
Constructs the termList as IIIF::Presentation::Resource
25 26 27 28 29 30 31 32 33 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 25 def term_list list_id = controller.request.original_url term_list = IIIF::Presentation::Resource.new('@id' => list_id) term_list['@context'] = 'http://iiif.io/api/search/1/context.json' term_list['@type'] = 'search:TermList' term_list['terms'] = terms term_list['ignored'] = ignored term_list.to_ordered_hash(force: true, include_context: false) end |
#terms ⇒ Array
Turn solr_response into array of hashes ‘try’ chain pattern copied from Blacklight::Suggest::Response#suggestions
39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/blacklight_iiif_search/iiif_suggest_response.rb', line 39 def terms terms_for_list = [] terms_array = solr_response.try(:[], 'suggest').try(:[], iiif_config[:suggester_name]).try(:[], query).try(:[], 'suggestions') || [] terms = terms_array.pluck('term') terms.sort.each do |term| term_hash = { match: term, url: iiif_search_url(term) } terms_for_list << term_hash end terms_for_list end |