Sha256: 21af369c4751a1c03723160f32738136d6c7e2bcbf7d82e1c7b6ed24acd42df6

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

module Spotlight
  module SolrDocument
    ##
    # Solr indexing strategy using Solr's Atomic Updates
    module AtomicUpdates
      def reindex
        return unless write?
        data = hash_for_solr_update(to_solr)

        blacklight_solr.update params: { commitWithin: 500 }, 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[Blacklight::Configuration.default_values[:index].timestamp_field] ||= { set: nil }
        output
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
blacklight-spotlight-2.2.1 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.2.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.1.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.2 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.1 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.0.rc6 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.0.rc5 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.0.rc4 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.0.rc3 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.0.rc2 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-2.0.0.rc1 app/models/concerns/spotlight/solr_document/atomic_updates.rb
blacklight-spotlight-1.5.1 app/models/concerns/spotlight/solr_document/atomic_updates.rb