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 ⇒ Valkyrie::Persistence::CustomQueryContainer
Construct the Valkyrie::Persistence::CustomQueryContainer object using this query service.
-
#find_all ⇒ Array<Valkyrie::Resource>
Find all of the Valkyrie Resources persisted in the Solr index.
-
#find_all_of_model(model:) ⇒ Array<Valkyrie::Resource>
Find all of the Valkyrie Resources of a model persisted in the Solr index.
-
#find_by(id:) ⇒ Valkyrie::Resource
Find resources by Valkyrie ID.
-
#find_by_alternate_identifier(alternate_identifier:) ⇒ Valkyrie::Resource
Find resources by a Valkyrie alternate identifier.
-
#find_inverse_references_by(resource:, property:) ⇒ Array<Valkyrie::Resource>
Find all of the resources referencing a given Valkyrie Resource using a specific property (e. g. find all resources referencing a parent resource as a collection using the property “member_of_collections”).
-
#find_many_by_ids(ids:) ⇒ Array<Valkyrie::Resource>
Find resources using a set of Valkyrie IDs.
-
#find_members(resource:, model: nil) ⇒ Array<Valkyrie::Resource>
Find all of the member resources for a given Valkyrie Resource.
-
#find_parents(resource:) ⇒ Array<Valkyrie::Resource>
Find all of the parent resources for a given Valkyrie Resource.
-
#find_references_by(resource:, property:) ⇒ Array<Valkyrie::Resource>
Find all of the resources referenced by a given Valkyrie Resource using a specific property.
-
#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 ⇒ Valkyrie::Persistence::CustomQueryContainer
Construct the Valkyrie::Persistence::CustomQueryContainer object using this query service
95 96 97 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 95 def custom_queries @custom_queries ||= ::Valkyrie::Persistence::CustomQueryContainer.new(query_service: self) end |
#find_all ⇒ Array<Valkyrie::Resource>
Find all of the Valkyrie Resources persisted in the Solr index
46 47 48 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 46 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>
Find all of the Valkyrie Resources of a model persisted in the Solr index
53 54 55 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 53 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
Find resources by Valkyrie ID
17 18 19 20 21 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 17 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
Find resources by a Valkyrie alternate identifier
26 27 28 29 30 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 26 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>
Find all of the resources referencing a given Valkyrie Resource using a specific property (e. g. find all resources referencing a parent resource as a collection using the property “member_of_collections”)
88 89 90 91 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 88 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>
Find resources using a set of Valkyrie IDs
35 36 37 38 39 40 41 42 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 35 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>
Find all of the member resources for a given Valkyrie Resource
67 68 69 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 67 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>
Find all of the parent resources for a given Valkyrie Resource
60 61 62 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 60 def find_parents(resource:) find_inverse_references_by(resource: resource, property: :member_ids) end |
#find_references_by(resource:, property:) ⇒ Array<Valkyrie::Resource>
Find all of the resources referenced by a given Valkyrie Resource using a specific property
75 76 77 78 79 80 81 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 75 def find_references_by(resource:, property:) if ordered_property?(resource: resource, property: property) Valkyrie::Persistence::Solr::Queries::FindOrderedReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run else Valkyrie::Persistence::Solr::Queries::FindReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run end end |