Sha256: e748f2f834ab4e7667eb70fa8344367df1386c426b69d0b550ec664dae080a38

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

module Spotlight::Resources
  # Base Resource indexer for objects in DOR
  class DorResource < Spotlight::Resource
    ##
    # Generate solr documents for the DOR resources identified by this object
    #
    # @return [Enumerator] an enumerator of solr document hashes for indexing
    def to_solr
      return to_enum :to_solr unless block_given?

      base_doc = super

      indexable_resources.each do |res|
        yield base_doc.merge(to_solr_document(res))
      end
    end

    def resource
      @resource ||= Spotlight::Dor::Resources.indexer.resource doc_id
    end

    private

    ##
    # Enumerate the resource, and any collection members, that should be indexed
    # into this exhibit
    #
    # @return [Enumerator] an enumerator of resources to index
    def indexable_resources
      return to_enum(:indexable_resources) unless block_given?

      yield resource

      resource.items.each do |r|
        yield r
      end
    end

    ##
    # Generate the solr document hash for a given resource by applying the current
    # indexer steps.
    #
    # @return [Hash]
    def to_solr_document(resource)
      Spotlight::Dor::Resources.indexer.solr_document(resource)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spotlight-dor-resources-0.0.6 app/models/spotlight/resources/dor_resource.rb
spotlight-dor-resources-0.0.5 app/models/spotlight/resources/dor_resource.rb
spotlight-dor-resources-0.0.4 app/models/spotlight/resources/dor_resource.rb