Sha256: dae583dc733bc32bedeccd0cb2b85aa13bb605c22555886e4e93018d1491aaba

Contents?: true

Size: 1.11 KB

Versions: 47

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true
module Valkyrie::Persistence::Solr
  # Composite object to make multiple custom indexers act like a single one, so
  # that upstream code doesn't have to know how to iterate over indexers.
  #
  # @see https://en.wikipedia.org/wiki/Composite_pattern
  class CompositeIndexer
    attr_reader :indexers

    # @param [Array<Object>] indexers
    def initialize(*indexers)
      @indexers = indexers
    end

    # Construct a new Instance object
    # @param [Valkyrie::Resource] resource
    def new(resource:)
      Instance.new(indexers, resource: resource)
    end

    # Class providing the common method interface for the Indexer
    class Instance
      attr_reader :indexers, :resource

      # @param [Array<Object>] indexers
      # @param [Valkyrie::Resource] resource
      def initialize(indexers, resource:)
        @resource = resource
        @indexers = indexers.map { |i| i.new(resource: resource) }
      end

      # Generate the Solr Documents from the indexers
      # @return [Array<Hash>]
      def to_solr
        indexers.map(&:to_solr).inject({}, &:merge)
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
valkyrie-3.5.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.4.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.3.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.1.5 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.1.4 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.1.3 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.1.2 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.1.1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.1.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.3 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.2 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.0.pre.rc.1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.0.pre.beta.3 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.0.pre.beta.2 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-3.0.0.pre.beta.1 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.2.0 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.1.2 lib/valkyrie/persistence/solr/composite_indexer.rb
valkyrie-2.1.1 lib/valkyrie/persistence/solr/composite_indexer.rb