Class: Spotlight::Search

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

Overview

Exhibit saved searches

Instance Method Summary collapse

Instance Method Details

#countObject



51
52
53
# File 'app/models/spotlight/search.rb', line 51

def count
  documents.size
end

#display_masthead?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/spotlight/search.rb', line 57

def display_masthead?
  masthead && masthead.display?
end

#documentsObject



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

#imagesObject



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_paramsObject

rubocop:enable Metrics/MethodLength



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

def search_params
  search_builder.with(query_params.with_indifferent_access).merge(facet: false, fl: default_search_fields)
end

#set_default_thumbnailObject

rubocop:disable Metrics/MethodLength



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/spotlight/search.rb', line 62

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_urlObject



22
23
24
# File 'app/models/spotlight/search.rb', line 22

def thumbnail_image_url
  thumbnail.image.thumb.url if thumbnail && thumbnail.image
end