Module: IiifPrint::LineageService

Defined in:
lib/iiif_print/lineage_service.rb

Overview

The purpose of this module is to encode lineage related services:

The ancestor and descendent_file_sets are useful for ensuring we index together related items. For example, when I have a work that is a book, and one file set per page of that book, when I search the book I want to find the text within the given book’s pages.

The methods of this module should be considered as defining an interface.

Class Method Summary collapse

Class Method Details

.ancestor_ids_for(object) ⇒ Array<String>

Note:

For those implementing their own lineage service, verify that you are not returning an array of



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/iiif_print/lineage_service.rb', line 22

def self.ancestor_ids_for(object)
  ancestor_ids ||= []
  # Yes, we're fetching the works, then compressing those into identifiers.  Because in the case
  # of slugs, we need not the identifier, but the slug as the id.
  IiifPrint.object_in_works(object).each do |work|
    ancestor_ids << ancestry_identifier_for(work)
    ancestor_ids += ancestor_ids_for(work) if work.respond_to?(:is_child) && work.is_child
  end
  # We must convert these to strings as Valkyrie's identifiers will be cast to hashes when we
  # attempt to write the SolrDocument.  Also, per documentation we return an Array of strings, not
  # an Array that might include Valkyrie::ID objects.
  ancestor_ids.flatten.compact.uniq.map(&:to_s)
end

.ancestry_identifier_for(work) ⇒ String

Given the :work return it’s identifier



43
44
45
# File 'lib/iiif_print/lineage_service.rb', line 43

def self.ancestry_identifier_for(work)
  IiifPrint.config.ancestory_identifier_function.call(work)
end

.descendent_member_ids_for(object) ⇒ Array<String> Also known as: descendent_file_set_ids_for



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/iiif_print/lineage_service.rb', line 50

def self.descendent_member_ids_for(object)
  return unless object.respond_to?(:member_ids)
  # enables us to return parents when searching for child OCR
  child_ids = object.member_ids
  # add in child works & their child works & filesets, recursively
  IiifPrint.object_ordered_works(object)&.each do |child|
    child_ids += Array.wrap(descendent_member_ids_for(child))
  end
  # We must convert these to strings as Valkyrie's identifiers will be cast to hashes when we
  # attempt to write the SolrDocument.
  child_ids.flatten.compact.map(&:to_s).uniq
end