Sha256: e2e06b0309376ef7fc960b7376184f056899090ddf2a12f4be936f0383a5568c

Contents?: true

Size: 1.49 KB

Versions: 26

Compression:

Stored size: 1.49 KB

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

    # @param [RSolr::Client] connection
    # @param [ResourceFactory] resource_factory
    # @param [Class] model
    def initialize(connection:, resource_factory:, model: nil)
      @connection = connection
      @resource_factory = resource_factory
      @model = model
    end

    # Iterate over each Solr Document and convert each Document into a Valkyrie Resource
    # @return [Array<Valkyrie::Resource>]
    def run
      enum_for(:each)
    end

    # Queries for all Documents in the Solr index
    # For each Document, it yields the Valkyrie Resource which was converted from it
    # @yield [Valkyrie::Resource]
    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

    # Generates the Solr query for retrieving all Documents in the index
    # If a model is specified for the query, it is scoped to that Valkyrie resource type
    # @return [String]
    def query
      if !model
        "*:*"
      else
        "#{Valkyrie::Persistence::Solr::Queries::MODEL}:#{model}"
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
valkyrie-2.0.2 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.1 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC10 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC9 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.7.1 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC8 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.7.0 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC7 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC6 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC5 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC4 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.6.0 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.5.1 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC3 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.5.0 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.5.0.RC2 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.5.0.RC1 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-2.0.0.RC1 lib/valkyrie/persistence/solr/queries/find_all_query.rb
valkyrie-1.4.0 lib/valkyrie/persistence/solr/queries/find_all_query.rb