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.23.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.22.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.21.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.20.3 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.20.2 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.20.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.20.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.19.2 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.19.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.19.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.18.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.17.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.17.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.16.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.15.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.14.2 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.14.1 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.14.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.13.0 app/models/concerns/spotlight/solr_document/finder.rb
blacklight-spotlight-0.12.1 app/models/concerns/spotlight/solr_document/finder.rb