Sha256: c529acd8ecfbff454360db8e9e2c4c8a8b92993e4ccfe31dc1c1ef3ce7f9785a

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module Spotlight
  # Mixin for retrieving solr documents for a specific exhibit
  module ExhibitDocuments
    ##
    # Retrieve all the solr documents associated with this exhibit, appropriately
    # filtered by the exhibit-specific solr field.
    #
    # @return [Enumerable<SolrDocument>]
    def solr_documents
      return to_enum(:solr_documents) unless block_given?

      start = 0
      response = repository.search(exhibit_search_params.merge(start: start))

      while response.documents.present?
        response.documents.each { |x| yield x }
        start += response.documents.length
        response = repository.search(exhibit_search_params.merge(start: start))
      end
    end

    private

    def exhibit_search_params
      params = { q: '*:*', fl: '*' }
      params[:fq] ||= []
      params[:fq] << solr_data if Spotlight::Engine.config.filter_resources_by_exhibit
      params
    end

    def repository
      @repository ||= Blacklight.repository_class.new(blacklight_config) if Blacklight.respond_to? :repository_class
      @repository ||= Blacklight::Solr::Repository.new(blacklight_config)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
blacklight-spotlight-0.9.2 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-0.9.1 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-0.9.0 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-0.8.2 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-0.8.1 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-0.8.0 app/models/concerns/spotlight/exhibit_documents.rb