Class: Spotlight::Search

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Includes:
SearchHelper, Translatables
Defined in:
app/models/spotlight/search.rb

Overview

Exhibit saved searches

Instance Method Summary collapse

Methods included from SearchHelper

#search_service, #search_service_context

Instance Method Details

#countObject



61
62
63
64
65
# File 'app/models/spotlight/search.rb', line 61

def count
  @count ||= Rails.cache.fetch([exhibit, self, 'count']) do
    documents.size
  end
end

#display_masthead?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/spotlight/search.rb', line 73

def display_masthead?
  masthead&.display?
end

#documentsObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/spotlight/search.rb', line 48

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

#full_titleObject



38
39
40
# File 'app/models/spotlight/search.rb', line 38

def full_title
  [title, subtitle.presence].compact.join(' ยท ')
end

#merge_params_for_search(params, blacklight_config) ⇒ Object



81
82
83
84
85
# File 'app/models/spotlight/search.rb', line 81

def merge_params_for_search(params, blacklight_config)
  base_query = Blacklight::SearchState.new((query_params || {}), blacklight_config)
  user_query = Blacklight::SearchState.new(params, blacklight_config).to_h
  base_query.params_for_search(user_query).merge(user_query.slice(:page))
end

#query_paramsObject



67
68
69
# File 'app/models/spotlight/search.rb', line 67

def query_params
  super || {}.with_indifferent_access
end

#search_paramsObject



77
78
79
# File 'app/models/spotlight/search.rb', line 77

def search_params
  search_service.search_builder.with((query_params || {}).with_indifferent_access).merge(facet: false)
end

#thumbnail_image_urlObject



42
43
44
45
46
# File 'app/models/spotlight/search.rb', line 42

def thumbnail_image_url
  return unless thumbnail&.iiif_url

  thumbnail.iiif_url
end