Module: Hyrax::Adapters::NestingIndexAdapter

Defined in:
app/services/hyrax/adapters/nesting_index_adapter.rb

Constant Summary collapse

FULL_REINDEX =
"full"
LIMITED_REINDEX =
"limited"

Providing interface for a Samvera::NestingIndexer::Adapter collapse

Supporting methods for interface implementation collapse

Class Method Details

.add_nesting_attributes(solr_doc:, ancestors:, parent_ids:, pathnames:, depth:) ⇒ SolrDocument

Parameters:

  • solr_doc (SolrDocument)
  • ancestors (Array)
  • parent_ids (Array)
  • pathnames (Array)
  • depth (Array)

    the object's deepest nesting depth

Returns:


105
106
107
108
109
110
111
112
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 105

def self.add_nesting_attributes(solr_doc:, ancestors:, parent_ids:, pathnames:, depth:)
  solr_doc[solr_field_name_for_storing_ancestors] = ancestors
  solr_doc[solr_field_name_for_storing_parent_ids] = parent_ids
  solr_doc[solr_field_name_for_storing_pathnames] = pathnames
  solr_doc[solr_field_name_for_deepest_nested_depth] = depth
  Hyrax::SolrService.add(solr_doc, commit: true)
  solr_doc
end

.each_child_document_of(document:, extent:) { ... } ⇒ void

This method returns an undefined value.

Parameters:

  • document (Samvera::NestingIndexer::Documents::IndexDocument)
  • extent (String)

    if not “full” or nil, doesn't yield children for reindexing

Yields:

  • Samvera::NestingIndexer::Documents::IndexDocument


122
123
124
125
126
127
128
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 122

def self.each_child_document_of(document:, extent:, &block)
  raw_child_solr_documents_of(parent_document: document).each do |solr_document|
    child_document = coerce_solr_document_to_index_document(original_solr_document: solr_document, id: solr_document.fetch('id'))
    # during light reindexing, we want to reindex the child only if fields aren't already there
    block.call(child_document) if full_reindex?(extent: extent) || child_document.pathnames.empty?
  end
end

.each_perservation_document_id_and_parent_ids {|id, parent_id| ... } ⇒ Object

Yield Parameters:

  • id (String)
  • parent_id (Array<String>)

See Also:

  • FULL_REINDEX)

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 57

def self.each_perservation_document_id_and_parent_ids(&block) # rubocop:disable Lint/UnusedMethodArgument
  ActiveFedora::Base.descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true).each do |uri|
    id = Hyrax.config.translate_uri_to_id.call(uri)
    object = ActiveFedora::Base.find(id)
    parent_ids = object.try(:member_of_collection_ids) || []

    # note: we do not yield when the object has parents. Calling the nested indexer for the
    # top id will reindex all descendants as well.
    if object.try(:use_nested_reindexing?)
      yield(id, parent_ids) if parent_ids.empty?
    else
      Rails.logger.info "Re-indexing via to_solr ... #{id}"
      Hyrax::SolrService.add(object.to_solr, commit: true)
    end
  end
end

.find_index_document_by(id:) ⇒ Object

Returns Samvera::NestingIndexer::Documents::IndexDocument.

Parameters:

  • id (String)

Returns:

  • Samvera::NestingIndexer::Documents::IndexDocument


46
47
48
49
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 46

def self.find_index_document_by(id:)
  solr_document = find_solr_document_by(id: id)
  coerce_solr_document_to_index_document(original_solr_document: solr_document, id: id)
end

.find_preservation_document_by(id:) ⇒ Object

Returns Samvera::NestingIndexer::Document::PreservationDocument.

Parameters:

  • id (String)

Returns:

  • Samvera::NestingIndexer::Document::PreservationDocument


15
16
17
18
19
20
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 15

def self.find_preservation_document_by(id:)
  # Not everything is guaranteed to have library_collection_ids
  # If it doesn't have it, what do we do?
  parent_ids = find_preservation_parent_ids_for(id: id)
  Samvera::NestingIndexer::Documents::PreservationDocument.new(id: id, parent_ids: parent_ids)
end

.find_preservation_parent_ids_for(id:) ⇒ Object

Returns Samvera::NestingIndexer::Document::PreservationDocument.

Parameters:

  • id (String)

Returns:

  • Samvera::NestingIndexer::Document::PreservationDocument


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 27

def self.find_preservation_parent_ids_for(id:)
  # Not everything is guaranteed to have library_collection_ids
  # If it doesn't have it, what do we do?
  fedora_object = Hyrax::Base.uncached do
    fedora_object = ActiveFedora::Base.find(id)
  end

  if fedora_object.respond_to?(:member_of_collection_ids)
    fedora_object.member_of_collection_ids
  else
    []
  end
end

.nesting_configurationObject

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.


160
161
162
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 160

def self.nesting_configuration
  @nesting_configuration ||= Samvera::NestingIndexer.configuration
end

.write_nesting_document_to_index_layer(nesting_document:) ⇒ Object

From the nesting_document, we will need to add the nesting attributes to the underlying SOLR document for the object

Parameters:

  • nesting_document (Samvera::NestingIndexer::Documents::IndexDocument)

Returns:

  • Hash - the attributes written to the indexing layer


81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 81

def self.write_nesting_document_to_index_layer(nesting_document:)
  solr_doc = Hyrax::Base.uncached do
    ActiveFedora::Base.find(nesting_document.id).to_solr # What is the current state of the solr document
  end

  # Now add the details from the nesting indexer to the document
  add_nesting_attributes(
    solr_doc: solr_doc,
    ancestors: nesting_document.ancestors,
    parent_ids: nesting_document.parent_ids,
    pathnames: nesting_document.pathnames,
    depth: nesting_document.deepest_nested_depth
  )
end