Class: Valkyrie::Persistence::Solr::Queries::FindManyByIdsQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ids, connection:, resource_factory:) ⇒ FindManyByIdsQuery

Returns a new instance of FindManyByIdsQuery.

Parameters:



10
11
12
13
14
# File 'lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb', line 10

def initialize(ids, connection:, resource_factory:)
  @ids = ids
  @connection = connection
  @resource_factory = resource_factory
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



4
5
6
# File 'lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb', line 4

def connection
  @connection
end

#idsObject

Returns the value of attribute ids.



5
6
7
# File 'lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb', line 5

def ids
  @ids
end

#resource_factoryObject (readonly)

Returns the value of attribute resource_factory.



4
5
6
# File 'lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb', line 4

def resource_factory
  @resource_factory
end

Instance Method Details

#resourcesArray<Hash>

Note:

this uses the “OR” operator for concatenating IDs and requests 1000000000 Documents

Query Solr for for all documents with the IDs in the requested field

Returns:

  • (Array<Hash>)


25
26
27
28
# File 'lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb', line 25

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

#runArray<Valkyrie::Resource>

Iterate over each Solr Document and convert each Document into a Valkyrie Resource

Returns:



18
19
20
# File 'lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb', line 18

def run
  resources.map { |solr_resource| resource_factory.to_resource(object: solr_resource) }
end