Class: Valkyrie::Persistence::Solr::Queries::FindManyByIdsQuery
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::Queries::FindManyByIdsQuery
- Defined in:
- lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
-
#initialize(ids, connection:, resource_factory:) ⇒ FindManyByIdsQuery
constructor
A new instance of FindManyByIdsQuery.
-
#resources ⇒ Array<Hash>
Query Solr for for all documents with the IDs in the requested field.
-
#run ⇒ Array<Valkyrie::Resource>
Iterate over each Solr Document and convert each Document into a Valkyrie Resource.
Constructor Details
#initialize(ids, connection:, resource_factory:) ⇒ FindManyByIdsQuery
Returns a new instance of FindManyByIdsQuery.
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
#connection ⇒ Object (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 |
#ids ⇒ Object
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_factory ⇒ Object (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
#resources ⇒ Array<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
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 |
#run ⇒ Array<Valkyrie::Resource>
Iterate over each Solr Document and convert each Document into a Valkyrie Resource
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 |