Sha256: 0a9fee8010900ef02d2c593b4adc20279a1352574150741e04d37c62eccee721

Contents?: true

Size: 1.42 KB

Versions: 29

Compression:

Stored size: 1.42 KB

Contents

module Spotlight
  ##
  # Proxy update requests to Solr and inject spotlight's exhibit
  # specific fields.
  #
  # This is an example of how you could integrate external indexing
  # workflows with exhibit-specific content
  class SolrController < Spotlight::ApplicationController
    include Blacklight::SearchHelper

    before_action :authenticate_user!
    before_action :validate_writable_index!

    load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
    delegate :blacklight_config, to: :current_exhibit

    def update
      authorize! :update_solr, @exhibit

      data = solr_documents

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

      if respond_to? :head
        head :ok
      else
        render nothing: true
      end
    end

    private

    def solr_documents
      req = ActiveSupport::JSON.decode(json_content)

      Array.wrap(req).map do |r|
        blacklight_config.document_model.new(r).to_solr.merge(@exhibit.solr_data).merge(r)
      end
    end

    def json_content
      if params[:resources_json_upload]
        params[:resources_json_upload][:json].read
      else
        request.body.read
      end
    end

    def validate_writable_index!
      return if Spotlight::Engine.config.writable_index

      render plain: 'Spotlight is unable to write to solr', status: 409
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
blacklight-spotlight-1.5.1 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.4.1 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.4.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.3.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.2.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.1.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.0.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.0.0.alpha2 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-1.0.0.alpha1 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.34.1 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.34.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.33.3 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.33.2 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.33.1 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.33.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.32.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.31.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.30.0 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.29.1 app/controllers/spotlight/solr_controller.rb
blacklight-spotlight-0.29.0 app/controllers/spotlight/solr_controller.rb