Sha256: a3f2576d5f4094106d5671dab48d0253f3941874a4c17c2efc521ba1e6cc6b75

Contents?: true

Size: 1.11 KB

Versions: 49

Compression:

Stored size: 1.11 KB

Contents

module Spotlight
  module SolrDocument
    ##
    # Finder methods for SolrDocuments
    module Finder
      extend ActiveSupport::Concern

      ##
      # Class level finder methods for documents
      module ClassMethods
        def find(id)
          solr_response = index.find(id)
          solr_response.documents.first
        end

        def index
          @index ||= blacklight_config.repository_class.new(blacklight_config)
        end

        def find_each
          return to_enum(:find_each) unless block_given?

          start = 0
          search_params = { q: '*:*', fl: 'id', facet: false }
          response = index.search(search_params.merge(start: start))

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

        protected

        def blacklight_config
          @conf ||= Spotlight::Engine.blacklight_config
        end
      end

      def blacklight_solr
        self.class.index.connection
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
blacklight-spotlight-0.34.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.34.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.33.3 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.33.2 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.33.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.33.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.32.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.31.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.30.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.29.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.29.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.28.3 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.28.2 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.28.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.28.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.27.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.26.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.26.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.25.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.24.0 app/models/concerns/spotlight/solr_document/finder.rb