Class: Spotlight::Search
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spotlight::Search
- Extended by:
- FriendlyId
- Includes:
- DefaultThumbnailable
- Defined in:
- app/models/spotlight/search.rb
Overview
Exhibit saved searches
Instance Method Summary collapse
- #display_masthead? ⇒ Boolean
- #documents ⇒ Object
- #images ⇒ Object
-
#search_params ⇒ Object
rubocop:enable Metrics/MethodLength.
-
#set_default_thumbnail ⇒ Object
rubocop:disable Metrics/MethodLength.
- #thumbnail_image_url ⇒ Object
Instance Method Details
#display_masthead? ⇒ Boolean
53 54 55 |
# File 'app/models/spotlight/search.rb', line 53 def display_masthead? masthead && masthead.display? end |
#documents ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/spotlight/search.rb', line 38 def documents start = 0 response = repository.search(search_params.start(start)) return to_enum(:documents) { response['response']['numFound'] } unless block_given? while response.documents.present? response.documents.each { |x| yield x } start += response.documents.length response = repository.search(search_params.start(start)) end end |
#images ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/spotlight/search.rb', line 26 def images return enum_for(:images) { documents.size } unless block_given? documents.each do |doc| yield [ doc.first(blacklight_config.document_model.unique_key), doc.first(blacklight_config.index.title_field), doc.first(blacklight_config.index.thumbnail_field) ] end end |
#search_params ⇒ Object
rubocop:enable Metrics/MethodLength
73 74 75 |
# File 'app/models/spotlight/search.rb', line 73 def search_params search_builder.with(query_params.with_indifferent_access).merge(facet: false, fl: default_search_fields) end |
#set_default_thumbnail ⇒ Object
rubocop:disable Metrics/MethodLength
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/spotlight/search.rb', line 58 def set_default_thumbnail self.thumbnail ||= begin return unless Spotlight::Engine.config.full_image_field doc = documents.detect { |x| x.first(Spotlight::Engine.config.full_image_field) } if doc create_thumbnail( source: 'exhibit', document_global_id: doc.to_global_id.to_s, remote_image_url: doc.first(Spotlight::Engine.config.full_image_field) ) end end end |
#thumbnail_image_url ⇒ Object
22 23 24 |
# File 'app/models/spotlight/search.rb', line 22 def thumbnail_image_url thumbnail.image.thumb.url if thumbnail && thumbnail.image end |