Sha256: 2dbb3a338c8a3132d18a10f7ee7c4148c194b8334d66561e2aedf8e49d7ac1ce

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Spotlight::SolrDocument
  module Finder
    
    extend ActiveSupport::Concern

    module ClassMethods
      def find(id)
        solr_params = {id: id, qt: 'document'}
        solr_response = get_solr_response(solr_params)
        raise Blacklight::Exceptions::InvalidSolrID, "Can't find #{id}" if solr_response.docs.empty?
        new(solr_response.docs.first, solr_response)
      end

      def blacklight_solr
        @solr ||=  RSolr.connect(blacklight_solr_config)
      end

      protected 

      def get_solr_response(params)
        path = blacklight_config.solr_path
        response = blacklight_solr.get(path, :params=> params)
        Blacklight::SolrResponse.new(response, params)
      rescue Errno::ECONNREFUSED => e
        raise Blacklight::Exceptions::ECONNREFUSED.new("Unable to connect to Solr instance using #{blacklight_solr.inspect}")
      end

      def blacklight_config
        @conf ||= CatalogController.blacklight_config
      end

      def blacklight_solr_config
        Blacklight.solr_config
      end
    end

    def blacklight_solr
      self.class.blacklight_solr
    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/finder.rb