Class: Valkyrie::Persistence::Solr::QueryService
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::QueryService
- Defined in:
- lib/valkyrie/persistence/solr/query_service.rb
Overview
Query Service for Solr MetadataAdapter.
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
- #custom_queries ⇒ Object
-
#find_all ⇒ Array<Valkyrie::Resource>
All objects in the persistence backend.
-
#find_all_of_model(model:) ⇒ Array<Valkyrie::Resource>
All objects in the persistence backend with the given class.
-
#find_by(id:) ⇒ Valkyrie::Resource
The object being searched for.
-
#find_by_alternate_identifier(alternate_identifier:) ⇒ Valkyrie::Resource
The object being searched for.
-
#find_inverse_references_by(resource:, property:) ⇒ Array<Valkyrie::Resource>
All resources in the persistence backend which have the ID of the given ‘resource` in their `property` property.
-
#find_many_by_ids(ids:) ⇒ Array<Valkyrie::Resource>
All requested objects that were found.
-
#find_members(resource:, model: nil) ⇒ Array<Valkyrie::Resource>
Child objects of type ‘model` referenced by `resource`’s ‘member_ids` method.
-
#find_parents(resource:) ⇒ Array<Valkyrie::Resource>
All resources which are parents of the given ‘resource`.
-
#find_references_by(resource:, property:) ⇒ Array<Valkyrie::Resource>
All objects which are referenced by the ‘property` property on `resource`.
-
#initialize(connection:, resource_factory:) ⇒ QueryService
constructor
A new instance of QueryService.
Constructor Details
#initialize(connection:, resource_factory:) ⇒ QueryService
Returns a new instance of QueryService.
9 10 11 12 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 9 def initialize(connection:, resource_factory:) @connection = connection @resource_factory = resource_factory end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 6 def connection @connection end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 6 def resource_factory @resource_factory end |
Instance Method Details
#custom_queries ⇒ Object
69 70 71 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 69 def custom_queries @custom_queries ||= ::Valkyrie::Persistence::CustomQueryContainer.new(query_service: self) end |
#find_all ⇒ Array<Valkyrie::Resource>
Returns All objects in the persistence backend.
39 40 41 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 39 def find_all Valkyrie::Persistence::Solr::Queries::FindAllQuery.new(connection: connection, resource_factory: resource_factory).run end |
#find_all_of_model(model:) ⇒ Array<Valkyrie::Resource>
Returns All objects in the persistence backend with the given class.
44 45 46 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 44 def find_all_of_model(model:) Valkyrie::Persistence::Solr::Queries::FindAllQuery.new(connection: connection, resource_factory: resource_factory, model: model).run end |
#find_by(id:) ⇒ Valkyrie::Resource
Returns The object being searched for.
15 16 17 18 19 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 15 def find_by(id:) id = Valkyrie::ID.new(id.to_s) if id.is_a?(String) validate_id(id) Valkyrie::Persistence::Solr::Queries::FindByIdQuery.new(id, connection: connection, resource_factory: resource_factory).run end |
#find_by_alternate_identifier(alternate_identifier:) ⇒ Valkyrie::Resource
Returns The object being searched for.
22 23 24 25 26 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 22 def find_by_alternate_identifier(alternate_identifier:) alternate_identifier = Valkyrie::ID.new(alternate_identifier.to_s) if alternate_identifier.is_a?(String) validate_id(alternate_identifier) Valkyrie::Persistence::Solr::Queries::FindByAlternateIdentifierQuery.new(alternate_identifier, connection: connection, resource_factory: resource_factory).run end |
#find_inverse_references_by(resource:, property:) ⇒ Array<Valkyrie::Resource>
Returns All resources in the persistence backend which have the ID of the given ‘resource` in their `property` property. Not in order.
64 65 66 67 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 64 def find_inverse_references_by(resource:, property:) ensure_persisted(resource) Valkyrie::Persistence::Solr::Queries::FindInverseReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run end |
#find_many_by_ids(ids:) ⇒ Array<Valkyrie::Resource>
Returns All requested objects that were found.
29 30 31 32 33 34 35 36 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 29 def find_many_by_ids(ids:) ids.map! do |id| id = Valkyrie::ID.new(id.to_s) if id.is_a?(String) validate_id(id) id end Valkyrie::Persistence::Solr::Queries::FindManyByIdsQuery.new(ids, connection: connection, resource_factory: resource_factory).run end |
#find_members(resource:, model: nil) ⇒ Array<Valkyrie::Resource>
Returns child objects of type ‘model` referenced by `resource`’s ‘member_ids` method. Returned in order.
54 55 56 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 54 def find_members(resource:, model: nil) Valkyrie::Persistence::Solr::Queries::FindMembersQuery.new(resource: resource, model: model, connection: connection, resource_factory: resource_factory).run end |
#find_parents(resource:) ⇒ Array<Valkyrie::Resource>
Returns All resources which are parents of the given ‘resource`. This means the resource’s ‘id` appears in their `member_ids` array.
49 50 51 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 49 def find_parents(resource:) find_inverse_references_by(resource: resource, property: :member_ids) end |
#find_references_by(resource:, property:) ⇒ Array<Valkyrie::Resource>
Returns All objects which are referenced by the ‘property` property on `resource`. Not necessarily in order.
59 60 61 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 59 def find_references_by(resource:, property:) Valkyrie::Persistence::Solr::Queries::FindReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run end |