Module: IiifPrint::LineageService
- Defined in:
- lib/iiif_print/lineage_service.rb
Overview
The purpose of this module is to encode lineage related services:
-
ancestor_identifier_for
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
- .ancestor_ids_for(object) ⇒ Array<String>
-
.ancestry_identifier_for(work) ⇒ String
Given the :work return it’s identifier.
-
.descendent_member_ids_for(object) ⇒ Array<String>
(also: descendent_file_set_ids_for)
github.com/samvera/hyrax/blob/2b807fe101176d594129ef8a8fe466d3d03a372b/app/indexers/hyrax/work_indexer.rb#L15-L18 for “clarification” of the comingling of file_set_ids and member_ids.
Class Method Details
.ancestor_ids_for(object) ⇒ Array<String>
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
github.com/samvera/hyrax/blob/2b807fe101176d594129ef8a8fe466d3d03a372b/app/indexers/hyrax/work_indexer.rb#L15-L18 for “clarification” of the comingling of file_set_ids and member_ids
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/iiif_print/lineage_service.rb', line 54 def self.descendent_member_ids_for(object) return unless object.respond_to?(:member_ids) # enables us to return parents when searching for child OCR # # https://github.com/samvera/hydra-works/blob/c9b9dd0cf11de671920ba0a7161db68ccf9b7f6d/lib/hydra/works/models/concerns/work_behavior.rb#L90-L92 # # The Hydara::Works implementation of file_set_ids is "members.select(&:file_set?).map(&:id)"; # so no sense doing `object.file_set_ids + object.member_ids` file_set_ids = object.member_ids IiifPrint.object_ordered_works(object)&.each do |child| file_set_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. file_set_ids.flatten.uniq.compact.map(&:to_s) end |