Class: Samvera::NestingIndexer::Documents::IndexDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/samvera/nesting_indexer/documents.rb

Overview

A rudimentary representation of what is needed to reindex Solr documents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keywords = {}) ⇒ IndexDocument

Returns a new instance of IndexDocument.



38
39
40
41
42
43
# File 'lib/samvera/nesting_indexer/documents.rb', line 38

def initialize(keywords = {})
  @id = keywords.fetch(:id).to_s
  @parent_ids = Array(keywords.fetch(:parent_ids))
  @pathnames = Array(keywords.fetch(:pathnames))
  @ancestors = Array(keywords.fetch(:ancestors))
end

Instance Attribute Details

#ancestorsObject (readonly)

All of the :pathnames of each of the documents ancestors. If I have A, with parent B, and B has parents C and D then we have the following ancestors:

[D], [C], [D/B], [C/B]


89
90
91
# File 'lib/samvera/nesting_indexer/documents.rb', line 89

def ancestors
  @ancestors
end

#idObject (readonly)

Returns String The Fedora object’s PID.

Returns:

  • String The Fedora object’s PID



60
61
62
# File 'lib/samvera/nesting_indexer/documents.rb', line 60

def id
  @id
end

#parent_idsObject (readonly)

All of the direct parents of the Fedora document associated with the given PID.

This does not include grandparents, great-grandparents, etc.



68
69
70
# File 'lib/samvera/nesting_indexer/documents.rb', line 68

def parent_ids
  @parent_ids
end

#pathnamesObject (readonly)

All nodes in the graph are addressable by one or more pathnames.

If I have A, with parent B, and B has parents C and D, we have the following pathnames:

[D/B/A, C/B/A]

In the graph representation, we can get to A by going from D to B to A, or by going from C to B to A.



80
81
82
# File 'lib/samvera/nesting_indexer/documents.rb', line 80

def pathnames
  @pathnames
end

Instance Method Details

#deepest_nested_depthObject

The largest nesting depth of this document. If I have A ={ B ={ C and D ={ C, then deepest_nested_depth is 3.

Returns:

  • Integer

Since:

  • v1.0.0



98
99
100
# File 'lib/samvera/nesting_indexer/documents.rb', line 98

def deepest_nested_depth
  pathnames.map(&:length).max
end

#sorted_ancestorsObject



110
111
112
# File 'lib/samvera/nesting_indexer/documents.rb', line 110

def sorted_ancestors
  ancestors.sort
end

#sorted_parent_idsObject



102
103
104
# File 'lib/samvera/nesting_indexer/documents.rb', line 102

def sorted_parent_ids
  parent_ids.sort
end

#sorted_pathnamesObject



106
107
108
# File 'lib/samvera/nesting_indexer/documents.rb', line 106

def sorted_pathnames
  pathnames.sort
end

#to_hashHash<Symbol,>

Returns the Ruby hash representation of this index document.

Returns:

  • (Hash<Symbol,>)

    the Ruby hash representation of this index document.

Since:

  • v1.0.0



48
49
50
51
52
53
54
55
56
# File 'lib/samvera/nesting_indexer/documents.rb', line 48

def to_hash
  {
    id: id,
    parent_ids: parent_ids,
    pathnames: pathnames,
    ancestors: ancestors,
    deepest_nested_depth: deepest_nested_depth
  }
end