Class: Valkyrie::Persistence::Solr::Queries::FindByAlternateIdentifierQuery
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::Queries::FindByAlternateIdentifierQuery
- Defined in:
- lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb
Overview
Responsible for returning a single resource identified by an ID.
Instance Attribute Summary collapse
-
#alternate_identifier ⇒ String
Retrieve the string value for the alternate ID.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
-
#initialize(alternate_identifier, connection:, resource_factory:) ⇒ FindByAlternateIdentifierQuery
constructor
A new instance of FindByAlternateIdentifierQuery.
-
#resource ⇒ Hash
Query Solr for for the first document with the alternate ID in a field.
-
#run ⇒ Valkyrie::Resource
Constructs a Valkyrie Resource found using the alternate ID.
Constructor Details
#initialize(alternate_identifier, connection:, resource_factory:) ⇒ FindByAlternateIdentifierQuery
Returns a new instance of FindByAlternateIdentifierQuery.
11 12 13 14 15 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb', line 11 def initialize(alternate_identifier, connection:, resource_factory:) @alternate_identifier = alternate_identifier @connection = connection @resource_factory = resource_factory end |
Instance Attribute Details
#alternate_identifier ⇒ String
Retrieve the string value for the alternate ID
27 28 29 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb', line 27 def alternate_identifier @alternate_identifier.to_s end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb', line 5 def connection @connection end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
5 6 7 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb', line 5 def resource_factory @resource_factory end |
Instance Method Details
#resource ⇒ Hash
the field used here is alternate_ids_ssim and the value is prefixed by “id-”
Query Solr for for the first document with the alternate ID in a field
34 35 36 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb', line 34 def resource @resource ||= connection.get("select", params: { q: "alternate_ids_ssim:\"id-#{alternate_identifier}\"", fl: "*", rows: 1 })["response"]["docs"].first end |
#run ⇒ Valkyrie::Resource
Constructs a Valkyrie Resource found using the alternate ID
20 21 22 23 |
# File 'lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb', line 20 def run raise ::Valkyrie::Persistence::ObjectNotFoundError unless resource resource_factory.to_resource(object: resource) end |