Sha256: 89b20ab7c3ab9a61c57bc27a4c05720ea17848c298547f4bdde51fb2af16f603

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

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(&block)
      return to_enum(:solr_documents) unless block_given?

      start = 0
      search_params = exhibit_search_builder.merge(q: '*:*', fl: '*')

      response = repository.search(search_params.start(start).to_h)

      while response.documents.present?
        response.documents.each(&block)
        start += response.documents.length
        response = repository.search(search_params.start(start).to_h)
      end
    end

    def exhibit_search_builder
      blacklight_config.search_builder_class.new(exhibit_search_builder_context).except(:apply_permissive_visibility_filter)
    end

    private

    def exhibit_search_builder_context
      OpenStruct.new(blacklight_config: blacklight_config.tap { |x| x.current_exhibit = self })
    end

    def repository
      @repository ||= Blacklight.repository_class.new(blacklight_config)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
blacklight-spotlight-4.2.0 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-4.1.2 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-4.1.1 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-4.1.0 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-4.0.3 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-4.0.2 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-4.0.1 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-4.0.0 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta10 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta9 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta8 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta7 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta6 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta5 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta4 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta3 app/models/concerns/spotlight/exhibit_documents.rb
blacklight-spotlight-3.6.0.beta1 app/models/concerns/spotlight/exhibit_documents.rb