Sha256: 9409d7063fb1550f6a9996c6b094b8e23756359c6ed84012248345e6b6189f0a

Contents?: true

Size: 923 Bytes

Versions: 7

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true
module Valkyrie::Persistence::Solr::Queries
  # Responsible for efficiently returning all objects in the solr repository as
  # {Valkyrie::Resource}s
  class FindAllQuery
    attr_reader :connection, :resource_factory, :model
    def initialize(connection:, resource_factory:, model: nil)
      @connection = connection
      @resource_factory = resource_factory
      @model = model
    end

    def run
      enum_for(:each)
    end

    def each
      docs = DefaultPaginator.new
      while docs.has_next?
        docs = connection.paginate(docs.next_page, docs.per_page, "select", params: { q: query })["response"]["docs"]
        docs.each do |doc|
          yield resource_factory.to_resource(object: doc)
        end
      end
    end

    def query
      if !model
        "*:*"
      else
        "#{Valkyrie::Persistence::Solr::Queries::MODEL}:#{model}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
valkyrie-1.2.0.rc1 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.1.2 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.1.1 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.1.0 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.0.0 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.0.0.rc2 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.0.0.rc1 lib/valkyrie/persistence/solr/queries/find_all_query.rb