Sha256: 39ae9b96f588d451b29a43294b18de843790defd7edb3e4146216556d28c7c0a

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module IiifPrint
  module FileSetIndexer
    # Why `.decorate`?  In my tests for Rails 5.2, I'm not able to use the prepended nor included
    # blocks to assign a class_attribute when I "prepend" a module to the base class.  This method
    # allows me to handle that behavior.
    #
    # @param base [Class]
    # @return [Class] the given base, now decorated in all of it's glory
    def self.decorate(base)
      base.prepend(self)
      base.class_attribute :iiif_print_lineage_service, default: IiifPrint::LineageService
      base
    end

    def generate_solr_document
      super.tap do |solr_doc|
        # only UV viewable images should have is_page_of, it is only used for iiif search
        solr_doc['is_page_of_ssim'] = iiif_print_lineage_service.ancestor_ids_for(object) if object.mime_type&.match(/image/)
        # index for full text search
        text = IiifPrint::Data::WorkDerivatives.data(from: object, of_type: 'txt')
        text = text.tr("\n", ' ').squeeze(' ')
        solr_doc['all_text_timv'] = text
        solr_doc['all_text_tsimv'] = text
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iiif_print-1.0.0 app/indexers/concerns/iiif_print/file_set_indexer.rb