Sha256: 82c62314d220eaa07ebb48233f4b4d0eb26c7a0e9355ef49c1006228d5754c62

Contents?: true

Size: 1.12 KB

Versions: 47

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true
module Valkyrie::Persistence::Solr::Queries
  class FindManyByIdsQuery
    attr_reader :connection, :resource_factory
    attr_accessor :ids

    # @param [Array<Valkyrie::ID>] ids
    # @param [RSolr::Client] connection
    # @param [ResourceFactory] resource_factory
    def initialize(ids, connection:, resource_factory:)
      @ids = ids
      @connection = connection
      @resource_factory = resource_factory
    end

    # Iterate over each Solr Document and convert each Document into a Valkyrie Resource
    # @return [Array<Valkyrie::Resource>]
    def run
      resources.map { |solr_resource| resource_factory.to_resource(object: solr_resource) }
    end

    # Query Solr for for all documents with the IDs in the requested field
    # @note this uses the "OR" operator for concatenating IDs and requests 1000000000 Documents
    # @return [Array<Hash>]
    def resources
      id_query = ids.map { |id| "\"#{id}\"" }.join(' OR ')
      @resources ||= connection.get("select", params: { q: "id:(#{id_query})", fl: "*", defType: 'lucene', rows: 1_000_000_000 })["response"]["docs"]
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
valkyrie-3.5.0 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.4.0 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.3.0 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.1.5 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.1.4 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.1.3 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.1.2 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.1.1 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.1.0 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.3 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.2 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.1 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.0 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.0.pre.rc.1 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.0.pre.beta.3 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.0.pre.beta.2 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-3.0.0.pre.beta.1 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-2.2.0 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-2.1.2 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
valkyrie-2.1.1 lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb