Sha256: 78dc8c530d8f8575154df496f3de84553d1897dc7ec2147578d34c50b08aed4b

Contents?: true

Size: 1.1 KB

Versions: 24

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Spotlight
  module SolrDocument
    ##
    # Solr indexing strategy using Solr's Atomic Updates
    module AtomicUpdates
      def reindex(update_params: { commitWithin: 500 })
        return unless write?

        data = hash_for_solr_update(to_solr)

        blacklight_solr.update params: update_params, data: data.to_json, headers: { 'Content-Type' => 'application/json' } unless data.empty?
      end

      def write?
        Spotlight::Engine.config.writable_index
      end

      private

      def hash_for_solr_update(data)
        Array.wrap(data).map { |doc| convert_document_to_atomic_update_hash(doc) }.reject { |x| x.length <= 2 }
      end

      def convert_document_to_atomic_update_hash(doc)
        output = doc.each_with_object({}) do |(k, v), hash|
          hash[k] = if k.to_sym == self.class.unique_key.to_sym
                      v
                    else
                      { set: v }
                    end
        end
        output[Spotlight::Engine.blacklight_config.index.timestamp_field] ||= { set: nil }
        output
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.3.5 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.3.4 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.3.3 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.3.2 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.3.1 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.3.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.2.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.1.2 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.1.1 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.1.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.0.3 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.0.2 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.0.1 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-4.0.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-3.6.0.beta10 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-3.6.0.beta9 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-3.6.0.beta8 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-3.6.0.beta7 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-3.6.0.beta6 app/models/concerns/spotlight/solr_document/atomic_updates.rb