valkyrie 1.2.0.rc1 → 1.2.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +12 -4
  4. data/lib/valkyrie/persistence/composite_persister.rb +1 -1
  5. data/lib/valkyrie/persistence/fedora/list_node.rb +42 -3
  6. data/lib/valkyrie/persistence/fedora/metadata_adapter.rb +26 -0
  7. data/lib/valkyrie/persistence/fedora/ordered_list.rb +36 -5
  8. data/lib/valkyrie/persistence/fedora/ordered_reader.rb +6 -0
  9. data/lib/valkyrie/persistence/fedora/permissive_schema.rb +20 -1
  10. data/lib/valkyrie/persistence/fedora/persister.rb +33 -4
  11. data/lib/valkyrie/persistence/fedora/persister/alternate_identifier.rb +6 -0
  12. data/lib/valkyrie/persistence/fedora/persister/model_converter.rb +254 -4
  13. data/lib/valkyrie/persistence/fedora/persister/orm_converter.rb +250 -3
  14. data/lib/valkyrie/persistence/fedora/persister/resource_factory.rb +6 -0
  15. data/lib/valkyrie/persistence/fedora/query_service.rb +22 -4
  16. data/lib/valkyrie/persistence/memory/metadata_adapter.rb +2 -0
  17. data/lib/valkyrie/persistence/memory/persister.rb +11 -3
  18. data/lib/valkyrie/persistence/memory/query_service.rb +11 -0
  19. data/lib/valkyrie/persistence/postgres/metadata_adapter.rb +2 -0
  20. data/lib/valkyrie/persistence/postgres/orm.rb +4 -0
  21. data/lib/valkyrie/persistence/postgres/orm_converter.rb +62 -2
  22. data/lib/valkyrie/persistence/postgres/persister.rb +18 -7
  23. data/lib/valkyrie/persistence/postgres/query_service.rb +103 -11
  24. data/lib/valkyrie/persistence/postgres/resource_converter.rb +10 -0
  25. data/lib/valkyrie/persistence/postgres/resource_factory.rb +3 -0
  26. data/lib/valkyrie/persistence/solr/composite_indexer.rb +10 -0
  27. data/lib/valkyrie/persistence/solr/metadata_adapter.rb +7 -0
  28. data/lib/valkyrie/persistence/solr/model_converter.rb +137 -0
  29. data/lib/valkyrie/persistence/solr/orm_converter.rb +168 -0
  30. data/lib/valkyrie/persistence/solr/persister.rb +13 -5
  31. data/lib/valkyrie/persistence/solr/queries.rb +1 -0
  32. data/lib/valkyrie/persistence/solr/queries/default_paginator.rb +11 -1
  33. data/lib/valkyrie/persistence/solr/queries/find_all_query.rb +12 -0
  34. data/lib/valkyrie/persistence/solr/queries/find_by_alternate_identifier_query.rb +12 -0
  35. data/lib/valkyrie/persistence/solr/queries/find_by_id_query.rb +11 -0
  36. data/lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb +13 -0
  37. data/lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb +9 -0
  38. data/lib/valkyrie/persistence/solr/queries/find_members_query.rb +23 -0
  39. data/lib/valkyrie/persistence/solr/queries/find_ordered_references_query.rb +50 -0
  40. data/lib/valkyrie/persistence/solr/queries/find_references_query.rb +15 -0
  41. data/lib/valkyrie/persistence/solr/query_service.rb +47 -14
  42. data/lib/valkyrie/persistence/solr/repository.rb +21 -4
  43. data/lib/valkyrie/persistence/solr/resource_factory.rb +2 -0
  44. data/lib/valkyrie/resource.rb +1 -0
  45. data/lib/valkyrie/specs/shared_specs.rb +1 -0
  46. data/lib/valkyrie/specs/shared_specs/persister.rb +92 -2
  47. data/lib/valkyrie/specs/shared_specs/queries.rb +12 -0
  48. data/lib/valkyrie/specs/shared_specs/solr_indexer.rb +40 -0
  49. data/lib/valkyrie/storage/fedora.rb +0 -2
  50. data/lib/valkyrie/version.rb +1 -1
  51. metadata +4 -2
@@ -11,5 +11,6 @@ module Valkyrie::Persistence::Solr
11
11
  require 'valkyrie/persistence/solr/queries/find_inverse_references_query'
12
12
  require 'valkyrie/persistence/solr/queries/find_members_query'
13
13
  require 'valkyrie/persistence/solr/queries/find_references_query'
14
+ require 'valkyrie/persistence/solr/queries/find_ordered_references_query'
14
15
  end
15
16
  end
@@ -1,16 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
  module Valkyrie::Persistence::Solr::Queries
3
3
  # Acts as a null object representing the default case for paginating over solr
4
- # results. Often only used for the first iteration of a loop.
4
+ # results. Often only used for the first iteration of a loop, or to retrieve
5
+ # all Documents in an index.
5
6
  class DefaultPaginator
7
+ # Default parameter for the next page in search results in a Solr query request
8
+ # @see https://lucene.apache.org/solr/guide/pagination-of-results.html
9
+ # @return [Integer]
6
10
  def next_page
7
11
  1
8
12
  end
9
13
 
14
+ # Default parameter for the number of documents in a page of search results in a Solr query request
15
+ # @see https://lucene.apache.org/solr/guide/pagination-of-results.html
16
+ # @return [Integer]
10
17
  def per_page
11
18
  100
12
19
  end
13
20
 
21
+ # Default state for the whether or not additional pages of search results in a Solr query response exist
22
+ # @see https://lucene.apache.org/solr/guide/pagination-of-results.html
23
+ # @return [Boolean]
14
24
  def has_next?
15
25
  true
16
26
  end
@@ -4,16 +4,25 @@ module Valkyrie::Persistence::Solr::Queries
4
4
  # {Valkyrie::Resource}s
5
5
  class FindAllQuery
6
6
  attr_reader :connection, :resource_factory, :model
7
+
8
+ # @param [RSolr::Client] connection
9
+ # @param [ResourceFactory] resource_factory
10
+ # @param [Class] model
7
11
  def initialize(connection:, resource_factory:, model: nil)
8
12
  @connection = connection
9
13
  @resource_factory = resource_factory
10
14
  @model = model
11
15
  end
12
16
 
17
+ # Iterate over each Solr Document and convert each Document into a Valkyrie Resource
18
+ # @return [Array<Valkyrie::Resource>]
13
19
  def run
14
20
  enum_for(:each)
15
21
  end
16
22
 
23
+ # Queries for all Documents in the Solr index
24
+ # For each Document, it yields the Valkyrie Resource which was converted from it
25
+ # @yield [Valkyrie::Resource]
17
26
  def each
18
27
  docs = DefaultPaginator.new
19
28
  while docs.has_next?
@@ -24,6 +33,9 @@ module Valkyrie::Persistence::Solr::Queries
24
33
  end
25
34
  end
26
35
 
36
+ # Generates the Solr query for retrieving all Documents in the index
37
+ # If a model is specified for the query, it is scoped to that Valkyrie resource type
38
+ # @return [String]
27
39
  def query
28
40
  if !model
29
41
  "*:*"
@@ -4,21 +4,33 @@ module Valkyrie::Persistence::Solr::Queries
4
4
  class FindByAlternateIdentifierQuery
5
5
  attr_reader :connection, :resource_factory
6
6
  attr_writer :alternate_identifier
7
+
8
+ # @param [Valkyrie::ID] alternate_identifier
9
+ # @param [RSolr::Client] connection
10
+ # @param [ResourceFactory] resource_factory
7
11
  def initialize(alternate_identifier, connection:, resource_factory:)
8
12
  @alternate_identifier = alternate_identifier
9
13
  @connection = connection
10
14
  @resource_factory = resource_factory
11
15
  end
12
16
 
17
+ # Constructs a Valkyrie Resource found using the alternate ID
18
+ # @raise [Valkyrie::Persistence::ObjectNotFoundError]
19
+ # @return [Valkyrie::Resource]
13
20
  def run
14
21
  raise ::Valkyrie::Persistence::ObjectNotFoundError unless resource
15
22
  resource_factory.to_resource(object: resource)
16
23
  end
17
24
 
25
+ # Retrieve the string value for the alternate ID
26
+ # @return [String]
18
27
  def alternate_identifier
19
28
  @alternate_identifier.to_s
20
29
  end
21
30
 
31
+ # Query Solr for for the first document with the alternate ID in a field
32
+ # @note the field used here is alternate_ids_ssim and the value is prefixed by "id-"
33
+ # @return [Hash]
22
34
  def resource
23
35
  connection.get("select", params: { q: "alternate_ids_ssim:\"id-#{alternate_identifier}\"", fl: "*", rows: 1 })["response"]["docs"].first
24
36
  end
@@ -4,21 +4,32 @@ module Valkyrie::Persistence::Solr::Queries
4
4
  class FindByIdQuery
5
5
  attr_reader :connection, :resource_factory
6
6
  attr_writer :id
7
+
8
+ # @param [Valkyrie::ID] id
9
+ # @param [RSolr::Client] connection
10
+ # @param [ResourceFactory] resource_factory
7
11
  def initialize(id, connection:, resource_factory:)
8
12
  @id = id
9
13
  @connection = connection
10
14
  @resource_factory = resource_factory
11
15
  end
12
16
 
17
+ # Constructs a Valkyrie Resource found using the ID
18
+ # @raise [Valkyrie::Persistence::ObjectNotFoundError]
19
+ # @return [Valkyrie::Resource]
13
20
  def run
14
21
  raise ::Valkyrie::Persistence::ObjectNotFoundError unless resource
15
22
  resource_factory.to_resource(object: resource)
16
23
  end
17
24
 
25
+ # Retrieve the string value for the ID
26
+ # @return [String]
18
27
  def id
19
28
  @id.to_s
20
29
  end
21
30
 
31
+ # Query Solr for for the first document with the ID in a field
32
+ # @return [Hash]
22
33
  def resource
23
34
  connection.get("select", params: { q: "id:\"#{id}\"", fl: "*", rows: 1 })["response"]["docs"].first
24
35
  end
@@ -4,6 +4,11 @@ module Valkyrie::Persistence::Solr::Queries
4
4
  # reference a {Valkyrie::Resource} in a given property.
5
5
  class FindInverseReferencesQuery
6
6
  attr_reader :resource, :property, :connection, :resource_factory
7
+
8
+ # @param [Valkyrie::Resource] resource
9
+ # @param [String] property
10
+ # @param [RSolr::Client] connection
11
+ # @param [ResourceFactory] resource_factory
7
12
  def initialize(resource:, property:, connection:, resource_factory:)
8
13
  @resource = resource
9
14
  @property = property
@@ -11,10 +16,15 @@ module Valkyrie::Persistence::Solr::Queries
11
16
  @resource_factory = resource_factory
12
17
  end
13
18
 
19
+ # Iterate over each Solr Document and convert each Document into a Valkyrie Resource
20
+ # @return [Array<Valkyrie::Resource>]
14
21
  def run
15
22
  enum_for(:each)
16
23
  end
17
24
 
25
+ # Queries for all Documents in the Solr index
26
+ # For each Document, it yields the Valkyrie Resource which was converted from it
27
+ # @yield [Valkyrie::Resource]
18
28
  def each
19
29
  docs = DefaultPaginator.new
20
30
  while docs.has_next?
@@ -25,6 +35,9 @@ module Valkyrie::Persistence::Solr::Queries
25
35
  end
26
36
  end
27
37
 
38
+ # Query Solr for for all documents with the ID in the requested field
39
+ # @note the field used here is a _ssim dynamic field and the value is prefixed by "id-"
40
+ # @return [Hash]
28
41
  def query
29
42
  "#{property}_ssim:id-#{resource.id}"
30
43
  end
@@ -3,16 +3,25 @@ module Valkyrie::Persistence::Solr::Queries
3
3
  class FindManyByIdsQuery
4
4
  attr_reader :connection, :resource_factory
5
5
  attr_accessor :ids
6
+
7
+ # @param [Array<Valkyrie::ID>] ids
8
+ # @param [RSolr::Client] connection
9
+ # @param [ResourceFactory] resource_factory
6
10
  def initialize(ids, connection:, resource_factory:)
7
11
  @ids = ids
8
12
  @connection = connection
9
13
  @resource_factory = resource_factory
10
14
  end
11
15
 
16
+ # Iterate over each Solr Document and convert each Document into a Valkyrie Resource
17
+ # @return [Array<Valkyrie::Resource>]
12
18
  def run
13
19
  resources.map { |solr_resource| resource_factory.to_resource(object: solr_resource) }
14
20
  end
15
21
 
22
+ # Query Solr for for all documents with the IDs in the requested field
23
+ # @note this uses the "OR" operator for concatenating IDs and requests 1000000000 Documents
24
+ # @return [Array<Hash>]
16
25
  def resources
17
26
  id_query = ids.map { |id| "\"#{id}\"" }.join(' OR ')
18
27
  @resources ||= connection.get("select", params: { q: "id:(#{id_query})", fl: "*", defType: 'lucene', rows: 1_000_000_000 })["response"]["docs"]
@@ -4,6 +4,11 @@ module Valkyrie::Persistence::Solr::Queries
4
4
  # {Valkyrie::Resource}s
5
5
  class FindMembersQuery
6
6
  attr_reader :resource, :connection, :resource_factory, :model
7
+
8
+ # @param [Valkyrie::Resource] resource
9
+ # @param [RSolr::Client] connection
10
+ # @param [ResourceFactory] resource_factory
11
+ # @param [Class] model
7
12
  def initialize(resource:, connection:, resource_factory:, model:)
8
13
  @resource = resource
9
14
  @connection = connection
@@ -11,10 +16,16 @@ module Valkyrie::Persistence::Solr::Queries
11
16
  @model = model
12
17
  end
13
18
 
19
+ # Iterate over each Solr Document and convert each Document into a Valkyrie Resource
20
+ # @return [Array<Valkyrie::Resource>]
14
21
  def run
15
22
  enum_for(:each)
16
23
  end
17
24
 
25
+ # Queries for all member Documents in the Solr index
26
+ # For each Document, it yields the Valkyrie Resource which was converted from it
27
+ # Results are ordered by the member IDs specified in the Valkyrie Resource attribute
28
+ # @yield [Valkyrie::Resource]
18
29
  def each
19
30
  return [] unless resource.id.present?
20
31
  unordered_members.sort_by { |x| member_ids.index(x.id) }.each do |member|
@@ -22,12 +33,17 @@ module Valkyrie::Persistence::Solr::Queries
22
33
  end
23
34
  end
24
35
 
36
+ # Retrieving the Solr Documents for the member resources, construct Valkyrie Resources for each
37
+ # @return [Array<Valkyrie::Resource>]
25
38
  def unordered_members
26
39
  docs.map do |doc|
27
40
  resource_factory.to_resource(object: doc)
28
41
  end
29
42
  end
30
43
 
44
+ # Query Solr for all members of the Valkyrie Resource
45
+ # If a model is specified, this is used to filter the results
46
+ # @return [Array<Hash>]
31
47
  def docs
32
48
  options = { q: query, rows: 1_000_000_000 }
33
49
  options[:fq] = "{!raw f=internal_resource_ssim}#{model}" if model
@@ -36,14 +52,21 @@ module Valkyrie::Persistence::Solr::Queries
36
52
  result["response"]["docs"]
37
53
  end
38
54
 
55
+ # Access the IDs of the members for the Valkyrie Resource
56
+ # @return [Array<Valkyrie::ID>]
39
57
  def member_ids
40
58
  Array.wrap(resource.member_ids)
41
59
  end
42
60
 
61
+ # Generate the Solr join query using the id_ssi field
62
+ # @see https://lucene.apache.org/solr/guide/other-parsers.html#join-query-parser
63
+ # @return [String]
43
64
  def query
44
65
  "{!join from=#{MEMBER_IDS} to=join_id_ssi}id:#{id}"
45
66
  end
46
67
 
68
+ # Retrieve the string value for the ID
69
+ # @return [String]
47
70
  def id
48
71
  resource.id.to_s
49
72
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module Valkyrie::Persistence::Solr::Queries
3
+ # Responsible for returning all {Valkyrie::Resource}s which are referenced in
4
+ # a given {Valkyrie::Resource}'s property, in the order given in that property.
5
+ class FindOrderedReferencesQuery
6
+ attr_reader :resource, :property, :connection, :resource_factory
7
+ def initialize(resource:, property:, connection:, resource_factory:)
8
+ @resource = resource
9
+ @property = property
10
+ @connection = connection
11
+ @resource_factory = resource_factory
12
+ end
13
+
14
+ def run
15
+ enum_for(:each)
16
+ end
17
+
18
+ def each
19
+ # map them off of the property to fix solr's deduplication
20
+ property_values.map { |id| unordered_members.find { |member| member.id == id } } .each do |value|
21
+ yield value
22
+ end
23
+ end
24
+
25
+ def unordered_members
26
+ docs.map do |doc|
27
+ resource_factory.to_resource(object: doc)
28
+ end
29
+ end
30
+
31
+ def docs
32
+ options = { q: query, rows: 1_000_000_000 }
33
+ options[:defType] = 'lucene'
34
+ result = connection.get("select", params: options)
35
+ result.fetch('response').fetch('docs')
36
+ end
37
+
38
+ def property_values
39
+ Array.wrap(resource[property])
40
+ end
41
+
42
+ def query
43
+ "{!join from=#{property}_ssim to=join_id_ssi}id:#{id}"
44
+ end
45
+
46
+ def id
47
+ resource.id.to_s
48
+ end
49
+ end
50
+ end
@@ -4,6 +4,11 @@ module Valkyrie::Persistence::Solr::Queries
4
4
  # a given {Valkyrie::Resource}'s property.
5
5
  class FindReferencesQuery
6
6
  attr_reader :resource, :property, :connection, :resource_factory
7
+
8
+ # @param [Valkyrie::Resource] resource
9
+ # @param [String] property resource property referencing other resources
10
+ # @param [RSolr::Client] connection
11
+ # @param [ResourceFactory] resource_factory
7
12
  def initialize(resource:, property:, connection:, resource_factory:)
8
13
  @resource = resource
9
14
  @property = property
@@ -11,10 +16,15 @@ module Valkyrie::Persistence::Solr::Queries
11
16
  @resource_factory = resource_factory
12
17
  end
13
18
 
19
+ # Iterate over each Solr Document and convert each Document into a Valkyrie Resource
20
+ # @return [Array<Valkyrie::Resource>]
14
21
  def run
15
22
  enum_for(:each)
16
23
  end
17
24
 
25
+ # Queries for all Documents in the Solr index
26
+ # For each Document, it yields the Valkyrie Resource which was converted from it
27
+ # @yield [Valkyrie::Resource]
18
28
  def each
19
29
  docs = DefaultPaginator.new
20
30
  while docs.has_next?
@@ -27,10 +37,15 @@ module Valkyrie::Persistence::Solr::Queries
27
37
  end
28
38
  end
29
39
 
40
+ # Generate the Solr join query using the id_ssi field
41
+ # @see https://lucene.apache.org/solr/guide/other-parsers.html#join-query-parser
42
+ # @return [String]
30
43
  def query
31
44
  "{!join from=#{property}_ssim to=join_id_ssi}id:#{id}"
32
45
  end
33
46
 
47
+ # Retrieve the string value for the ID
48
+ # @return [String]
34
49
  def id
35
50
  resource.id.to_s
36
51
  end
@@ -4,30 +4,34 @@ module Valkyrie::Persistence::Solr
4
4
  # Query Service for Solr MetadataAdapter.
5
5
  class QueryService
6
6
  attr_reader :connection, :resource_factory
7
-
8
- # @param connection [RSolr::Client]
9
- # @param resource_factory [Valkyrie::Persistence::Solr::ResourceFactory]
10
- # @note (see Valkyrie::Persistence::Memory::QueryService#initialize)
7
+ # @param [RSolr::Client] connection
8
+ # @param [Valkyrie::Persistence::Solr::ResourceFactory] resource_factory
11
9
  def initialize(connection:, resource_factory:)
12
10
  @connection = connection
13
11
  @resource_factory = resource_factory
14
12
  end
15
13
 
16
- # (see Valkyrie::Persistence::Memory::QueryService#find_by)
14
+ # Find resources by Valkyrie ID
15
+ # @param [Valkyrie::ID] id
16
+ # @return [Valkyrie::Resource]
17
17
  def find_by(id:)
18
18
  id = Valkyrie::ID.new(id.to_s) if id.is_a?(String)
19
19
  validate_id(id)
20
20
  Valkyrie::Persistence::Solr::Queries::FindByIdQuery.new(id, connection: connection, resource_factory: resource_factory).run
21
21
  end
22
22
 
23
- # (see Valkyrie::Persistence::Memory::QueryService#find_by_alternate_identifier)
23
+ # Find resources by a Valkyrie alternate identifier
24
+ # @param [Valkyrie::ID] alternate_identifier
25
+ # @return [Valkyrie::Resource]
24
26
  def find_by_alternate_identifier(alternate_identifier:)
25
27
  alternate_identifier = Valkyrie::ID.new(alternate_identifier.to_s) if alternate_identifier.is_a?(String)
26
28
  validate_id(alternate_identifier)
27
29
  Valkyrie::Persistence::Solr::Queries::FindByAlternateIdentifierQuery.new(alternate_identifier, connection: connection, resource_factory: resource_factory).run
28
30
  end
29
31
 
30
- # (see Valkyrie::Persistence::Memory::QueryService#find_many_by_ids)
32
+ # Find resources using a set of Valkyrie IDs
33
+ # @param [Array<Valkyrie::ID>] ids
34
+ # @return [Array<Valkyrie::Resource>]
31
35
  def find_many_by_ids(ids:)
32
36
  ids.map! do |id|
33
37
  id = Valkyrie::ID.new(id.to_s) if id.is_a?(String)
@@ -37,49 +41,78 @@ module Valkyrie::Persistence::Solr
37
41
  Valkyrie::Persistence::Solr::Queries::FindManyByIdsQuery.new(ids, connection: connection, resource_factory: resource_factory).run
38
42
  end
39
43
 
40
- # (see Valkyrie::Persistence::Memory::QueryService#find_all)
44
+ # Find all of the Valkyrie Resources persisted in the Solr index
45
+ # @return [Array<Valkyrie::Resource>]
41
46
  def find_all
42
47
  Valkyrie::Persistence::Solr::Queries::FindAllQuery.new(connection: connection, resource_factory: resource_factory).run
43
48
  end
44
49
 
45
- # (see Valkyrie::Persistence::Memory::QueryService#find_all_of_model)
50
+ # Find all of the Valkyrie Resources of a model persisted in the Solr index
51
+ # @param [Class, String] model the Valkyrie::Resource Class
52
+ # @return [Array<Valkyrie::Resource>]
46
53
  def find_all_of_model(model:)
47
54
  Valkyrie::Persistence::Solr::Queries::FindAllQuery.new(connection: connection, resource_factory: resource_factory, model: model).run
48
55
  end
49
56
 
50
- # (see Valkyrie::Persistence::Memory::QueryService#find_parents)
57
+ # Find all of the parent resources for a given Valkyrie Resource
58
+ # @param [Valkyrie::Resource] member resource
59
+ # @return [Array<Valkyrie::Resource>] parent resources
51
60
  def find_parents(resource:)
52
61
  find_inverse_references_by(resource: resource, property: :member_ids)
53
62
  end
54
63
 
55
- # (see Valkyrie::Persistence::Memory::QueryService#find_members)
64
+ # Find all of the member resources for a given Valkyrie Resource
65
+ # @param [Valkyrie::Resource] parent resource
66
+ # @return [Array<Valkyrie::Resource>] member resources
56
67
  def find_members(resource:, model: nil)
57
68
  Valkyrie::Persistence::Solr::Queries::FindMembersQuery.new(resource: resource, model: model, connection: connection, resource_factory: resource_factory).run
58
69
  end
59
70
 
60
- # (see Valkyrie::Persistence::Memory::QueryService#find_references_by)
71
+ # Find all of the resources referenced by a given Valkyrie Resource using a specific property
72
+ # @param [Valkyrie::Resource] resource
73
+ # @param [Symbol, String] property
74
+ # @return [Array<Valkyrie::Resource>] referenced resources
61
75
  def find_references_by(resource:, property:)
62
- Valkyrie::Persistence::Solr::Queries::FindReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run
76
+ if ordered_property?(resource: resource, property: property)
77
+ Valkyrie::Persistence::Solr::Queries::FindOrderedReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run
78
+ else
79
+ Valkyrie::Persistence::Solr::Queries::FindReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run
80
+ end
63
81
  end
64
82
 
65
- # (see Valkyrie::Persistence::Memory::QueryService#find_inverse_references_by)
83
+ # Find all of the resources referencing a given Valkyrie Resource using a specific property
84
+ # (e. g. find all resources referencing a parent resource as a collection using the property "member_of_collections")
85
+ # @param [Valkyrie::Resource] referenced resource
86
+ # @param [Symbol, String] property
87
+ # @return [Array<Valkyrie::Resource>] related resources
66
88
  def find_inverse_references_by(resource:, property:)
67
89
  ensure_persisted(resource)
68
90
  Valkyrie::Persistence::Solr::Queries::FindInverseReferencesQuery.new(resource: resource, property: property, connection: connection, resource_factory: resource_factory).run
69
91
  end
70
92
 
93
+ # Construct the Valkyrie::Persistence::CustomQueryContainer object using this query service
94
+ # @return [Valkyrie::Persistence::CustomQueryContainer]
71
95
  def custom_queries
72
96
  @custom_queries ||= ::Valkyrie::Persistence::CustomQueryContainer.new(query_service: self)
73
97
  end
74
98
 
75
99
  private
76
100
 
101
+ # Determine whether or not a value is a Valkyrie ID
102
+ # @param [Object] id
103
+ # @return [Boolean]
77
104
  def validate_id(id)
78
105
  raise ArgumentError, 'id must be a Valkyrie::ID' unless id.is_a? Valkyrie::ID
79
106
  end
80
107
 
108
+ # Ensure that a given Valkyrie Resource has been persisted
109
+ # @param [Valkyrie::Resource] resource
81
110
  def ensure_persisted(resource)
82
111
  raise ArgumentError, 'resource is not saved' unless resource.persisted?
83
112
  end
113
+
114
+ def ordered_property?(resource:, property:)
115
+ resource.class.schema[property].meta.try(:[], :ordered)
116
+ end
84
117
  end
85
118
  end