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:, adapter:) ⇒ QueryService

Returns a new instance of QueryService.

Parameters:



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

#adapterObject (readonly)

Returns the value of attribute adapter.



6
7
8
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 6

def adapter
  @adapter
end

#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_queriesValkyrie::Persistence::CustomQueryContainer

Construct the Valkyrie::Persistence::CustomQueryContainer object using this query service



103
104
105
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 103

def custom_queries
  @custom_queries ||= ::Valkyrie::Persistence::CustomQueryContainer.new(query_service: self)
end

#find_allArray<Valkyrie::Resource>

Find all of the Valkyrie Resources persisted in the Solr index

Returns:



47
48
49
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 47

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

Parameters:

  • model (Class, String)

    the Valkyrie::Resource Class

Returns:



54
55
56
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 54

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

Parameters:

Returns:



18
19
20
21
22
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 18

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

Parameters:

Returns:



27
28
29
30
31
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 27

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:) ⇒ 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”)

Parameters:

Returns:

Raises:

  • (ArgumentError)


94
95
96
97
98
99
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 94

def find_inverse_references_by(resource: nil, id: nil, property:)
  raise ArgumentError, "Provide resource or id" unless resource || id
  ensure_persisted(resource) if resource
  id ||= resource.id
  Valkyrie::Persistence::Solr::Queries::FindInverseReferencesQuery.new(id: id, 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

Parameters:

Returns:



36
37
38
39
40
41
42
43
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 36

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

Parameters:

Returns:



68
69
70
71
72
73
74
75
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 68

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

Parameters:

Returns:



61
62
63
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 61

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

Parameters:

Returns:



81
82
83
84
85
86
87
# File 'lib/valkyrie/persistence/solr/query_service.rb', line 81

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