Module: Hyrax::Adapters::NestingIndexAdapter

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

Constant Summary collapse

FULL_REINDEX =
"full".freeze
LIMITED_REINDEX =
"limited".freeze

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

Parameters:

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

    the object's deepest nesting depth


95
96
97
98
99
100
101
102
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 95

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
  ActiveFedora::SolrService.add(solr_doc, commit: true)
  solr_doc
end

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

Parameters:

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

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

  • solr_field_name_for_ancestors (String)

    The SOLR field name we use to find children

Yields:

  • Samvera::NestingIndexer::Documents::IndexDocument


109
110
111
112
113
114
115
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 109

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

Samvera::NestingIndexer.reindex_all!(extent: FULL_REINDEX) rubocop:disable Lint/UnusedMethodArgument

Yield Parameters:

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

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 48

def self.each_perservation_document_id_and_parent_ids(&block)
  ActiveFedora::Base.descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true).each do |uri|
    id = ActiveFedora::Base.uri_to_id(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}"
      ActiveFedora::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


38
39
40
41
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 38

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


11
12
13
14
15
16
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 11

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


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 21

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 = ActiveFedora::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.


143
144
145
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 143

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


72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/services/hyrax/adapters/nesting_index_adapter.rb', line 72

def self.write_nesting_document_to_index_layer(nesting_document:)
  solr_doc = ActiveFedora::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