Module: Hyrax::Collections::NestedCollectionQueryService

Defined in:
app/services/hyrax/collections/nested_collection_query_service.rb

Defined Under Namespace

Classes: NestingAttributes

Class Method Summary collapse

Class Method Details

.available_child_collections(parent:, scope:, limit_to_id: nil) ⇒ Array<SolrDocument>

What possible collections can be nested within the given parent collection?



35
36
37
38
39
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 35

def self.available_child_collections(parent:, scope:, limit_to_id: nil)
  return [] unless parent.try(:nestable?)
  return [] unless scope.can?(:deposit, parent)
  query_solr(collection: parent, access: :read, scope: scope, limit_to_id: limit_to_id, nest_direction: :as_child).documents
end

.available_parent_collections(child:, scope:, limit_to_id: nil) ⇒ Array<SolrDocument>

What possible collections can the given child be nested within?



49
50
51
52
53
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 49

def self.available_parent_collections(child:, scope:, limit_to_id: nil)
  return [] unless child.try(:nestable?)
  return [] unless scope.can?(:read, child)
  query_solr(collection: child, access: :deposit, scope: scope, limit_to_id: limit_to_id, nest_direction: :as_parent).documents
end

.clean_lucene_error(builder:) ⇒ Blacklight::Solr::Request

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

clean query for !lucene error



100
101
102
103
104
105
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 100

def self.clean_lucene_error(builder:)
  # TODO: Need to investigate further to understand why these particular queries using the where cause fail when others in the app apparently work
  query = builder.query.to_hash
  query['q'].gsub!('{!lucene}', '') if query.key? 'q'
  query
end

.parent_and_child_can_nest?(parent:, child:, scope:) ⇒ Boolean

TODO:

Consider expanding from same collection type to a lookup table that says “This collection type can have within it, these collection types”

Note:

There is a short-circuit of logic; To be robust, we should ensure that the child and parent are in the corresponding available collections

Is it valid to nest the given child within the given parent?



118
119
120
121
122
123
124
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 118

def self.parent_and_child_can_nest?(parent:, child:, scope:)
  return false if parent == child # Short-circuit
  return false unless parent.collection_type_gid == child.collection_type_gid
  return false if available_parent_collections(child: child, scope: scope, limit_to_id: parent.id).none?
  return false if available_child_collections(parent: parent, scope: scope, limit_to_id: child.id).none?
  true
end

.parent_collections(child:, scope:, page: 1) ⇒ Blacklight::Solr::Response

What collections is the given child nested within?



64
65
66
67
68
69
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 64

def self.parent_collections(child:, scope:, page: 1)
  return [] unless child.try(:nestable?)
  query_builder = Hyrax::NestedCollectionsParentSearchBuilder.new(scope: scope, child: child, page: page)
  query = clean_lucene_error(builder: query_builder)
  scope.repository.search(query)
end

.valid_combined_nesting_depth?(parent:, child: nil, scope:) ⇒ Boolean

Does the nesting depth fall within defined limit?



134
135
136
137
138
139
140
# File 'app/services/hyrax/collections/nested_collection_query_service.rb', line 134

def self.valid_combined_nesting_depth?(parent:, child: nil, scope:)
  # We limit the total depth of collections to the size specified in the samvera-nesting_indexer configuration.
  child_depth = child_nesting_depth(child: child, scope: scope)
  parent_depth = parent_nesting_depth(parent: parent, scope: scope)
  return false if parent_depth + child_depth > Samvera::NestingIndexer.configuration.maximum_nesting_depth
  true
end