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
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
-
#count_all_of_model(model:) ⇒ Object
Count all of the Valkyrie Resources of a model persisted in the Solr index.
-
#custom_queries ⇒ Valkyrie::Persistence::CustomQueryContainer
Get the set of custom queries configured for this query service.
-
#find_all ⇒ Array<Valkyrie::Resource>
Get all objects.
-
#find_all_of_model(model:) ⇒ Array<Valkyrie::Resource>
Get all objects of a given model.
-
#find_by(id:) ⇒ Valkyrie::Resource
Get a single resource by ID.
-
#find_by_alternate_identifier(alternate_identifier:) ⇒ Valkyrie::Resource
Get a single resource by ‘alternate_identifier`.
-
#find_inverse_references_by(resource: nil, id: nil, property:, model: nil) ⇒ Array<Valkyrie::Resource>
Get all resources which link to a resource with a given property.
-
#find_many_by_ids(ids:) ⇒ Array<Valkyrie::Resource>
Get a batch of resources by ID.
-
#find_members(resource:, model: nil) ⇒ Array<Valkyrie::Resource>
Get all members of a given resource.
-
#find_parents(resource:) ⇒ Array<Valkyrie::Resource>
Find all parents of a given resource.
-
#find_references_by(resource:, property:, model: nil) ⇒ Array<Valkyrie::Resource>
Get all resources referenced from a resource with a given property.
-
#initialize(connection:, resource_factory:, adapter:) ⇒ QueryService
constructor
A new instance of QueryService.
Constructor Details
#initialize(connection:, resource_factory:, adapter:) ⇒ QueryService
Returns a new instance of QueryService.
9 10 11 12 13 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 9 def initialize(connection:, resource_factory:, adapter:) @connection = connection @resource_factory = resource_factory @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 6 def adapter @adapter end |
#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
#count_all_of_model(model:) ⇒ Object
Count all of the Valkyrie Resources of a model persisted in the Solr index
52 53 54 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 52 def count_all_of_model(model:) Valkyrie::Persistence::Solr::Queries::FindAllQuery.new(connection: connection, resource_factory: resource_factory, model: model).count end |
#custom_queries ⇒ Valkyrie::Persistence::CustomQueryContainer
Get the set of custom queries configured for this query service.
94 95 96 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 94 def custom_queries @custom_queries ||= ::Valkyrie::Persistence::CustomQueryContainer.new(query_service: self) end |
#find_all ⇒ Array<Valkyrie::Resource>
Get all objects.
40 41 42 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 40 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>
Get all objects of a given model.
45 46 47 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 45 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
Get a single resource by ID.
16 17 18 19 20 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 16 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
Get a single resource by ‘alternate_identifier`. Alternate identifiers are identifiers (like NOIDs, DOIs, ARKs, etc.) that are not the system-generated ID, but might be used to identify a resource in an application (e.g., to make shorter URLs).
23 24 25 26 27 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 23 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: nil, id: nil, property:, model: nil) ⇒ Array<Valkyrie::Resource>
Get all resources which link to a resource with a given property.
84 85 86 87 88 89 90 91 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 84 def find_inverse_references_by(resource: nil, id: nil, property:, model: nil) raise ArgumentError, "Provide resource or id" unless resource || id ensure_persisted(resource) if resource id ||= resource.id result = Valkyrie::Persistence::Solr::Queries::FindInverseReferencesQuery.new(id: id, property: property, connection: connection, resource_factory: resource_factory).run return result unless model result.select { |obj| obj.is_a?(model) } end |
#find_many_by_ids(ids:) ⇒ Array<Valkyrie::Resource>
Get a batch of resources by ID.
30 31 32 33 34 35 36 37 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 30 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>
Get all members of a given resource.
62 63 64 65 66 67 68 69 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 62 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 parents of a given resource.
57 58 59 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 57 def find_parents(resource:) find_inverse_references_by(resource: resource, property: :member_ids) end |
#find_references_by(resource:, property:, model: nil) ⇒ Array<Valkyrie::Resource>
Get all resources referenced from a resource with a given property.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 72 def find_references_by(resource:, property:, model: nil) result = 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 return result unless model result.select { |obj| obj.is_a?(model) } end |