Class: Spotlight::Search

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

Overview

Exhibit saved searches

Instance Method Summary collapse

Instance Method Details

#countObject



29
30
31
# File 'app/models/spotlight/search.rb', line 29

def count
  repository.search(search_builder.with(query_params).rows(0).merge(facet: false))['response']['numFound']
end

#display_masthead?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/spotlight/search.rb', line 53

def display_masthead?
  masthead && masthead.display?
end

#documentsObject



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

def documents
  return enum_for(:documents) unless block_given?

  Blacklight::Solr::Response.new(solr_response, {}).docs.each do |result|
    yield blacklight_config.document_model.new(result)
  end
end

#imagesObject



33
34
35
36
37
38
39
40
41
# File 'app/models/spotlight/search.rb', line 33

def images
  documents.map do |doc|
    [
      doc.first(blacklight_config.document_model.unique_key),
      doc.first(blacklight_config.index.title_field),
      doc.first(blacklight_config.index.thumbnail_field)
    ]
  end
end

#set_default_thumbnailObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/spotlight/search.rb', line 57

def set_default_thumbnail
  self.thumbnail ||= begin
    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



25
26
27
# File 'app/models/spotlight/search.rb', line 25

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