Sha256: 775215b9bf507024e33a8e7da21da457e0fd7f84c321e3da4ccb68c0f9d9c94a

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

module Spotlight::SolrDocument::AtomicUpdates

  def reindex
    data = hash_for_solr_update

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

  private
  def hash_for_solr_update
    data = to_solr
    data = [data] unless data.is_a? Array

    data.map do |doc|
      Hash[doc.map do |k,v|
        val = if k.to_sym == unique_key_field.to_sym
          v
        else
          { set: v }
        end

        [k,val]
      end]
    end.reject { |x| x.length <= 1 }
  end

  def unique_key_field
    if respond_to?(:blacklight_config)
      blacklight_config.solr_document_model.unique_key
    else
      'id'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-spotlight-0.2.0 app/models/concerns/spotlight/solr_document/atomic_updates.rb