Class: Valkyrie::Persistence::Solr::QueryService

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/solr/query_service.rb

Overview

Query Service for Solr MetadataAdapter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, resource_factory:) ⇒ QueryService

Returns a new instance of QueryService.

Parameters:



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

#connectionObject (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_factoryObject (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_queriesObject



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_allArray<Valkyrie::Resource>

Returns All objects in the persistence backend.

Returns:



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.

Parameters:

  • model (Class)

    Class to query for.

Returns:

  • (Array<Valkyrie::Resource>)

    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.

Parameters:

Returns:

Raises:



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.

Parameters:

  • alternate_identifier (Valkyrie::ID)

    The alternate identifier to query for.

Returns:

Raises:

  • (Valkyrie::Persistence::ObjectNotFoundError)

    Raised when the alternate identifier isn’t in the persistence backend.

  • (ArgumentError)

    Raised when alternate identifier is not a String or a Valkyrie::ID



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.

Parameters:

  • resource (Valkyrie::Resource)

    The resource which is being referenced by other resources.

  • property (Symbol)

    The property which, on other resources, is referencing the given ‘resource`

Returns:

  • (Array<Valkyrie::Resource>)

    All resources in the persistence backend which have the ID of the given ‘resource` in their `property` property. Not in order.

Raises:

  • (ArgumentError)

    Raised when the ID is not in the persistence backend.



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.

Parameters:

  • ids (Array<Valkyrie::ID, String>)

    The IDs to query for.

Returns:

Raises:

  • (ArgumentError)

    Raised when any ID is not a String or a Valkyrie::ID



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.

Parameters:

  • resource (Valkyrie::Resource)

    Model whose members are being searched for.

  • model (Class) (defaults to: nil)

    Class to query for. (optional)

Returns:

  • (Array<Valkyrie::Resource>)

    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.

Parameters:

Returns:

  • (Array<Valkyrie::Resource>)

    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.

Parameters:

  • resource (Valkyrie::Resource)

    Model whose property is being searched.

  • property (Symbol)

    Property which, on the ‘resource`, contains IDs which are to be de-referenced.

Returns:

  • (Array<Valkyrie::Resource>)

    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