Sha256: 960ff208b127dbb33767aa8d9564ea89169b9b8710db4b9f7bc826b507e39525

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

class Blacklight::SolrResponse < HashWithIndifferentAccess

  autoload :Spelling, 'blacklight/solr_response/spelling'
  autoload :Facets, 'blacklight/solr_response/facets'
  autoload :MoreLikeThis, 'blacklight/solr_response/more_like_this'

  attr_reader :request_params
  def initialize(data, request_params)
    super(data)
    @request_params = request_params
    extend Spelling
    extend Facets
    extend Response
    extend MoreLikeThis
  end

  def header
    self['responseHeader']
  end
  

  def update(other_hash) 
    other_hash.each_pair { |key, value| self[key] = value } 
    self 
  end 

  def params
      (header and header['params']) ? header['params'] : request_params
  end

  def rows
      params[:rows].to_i
  end

  def docs
    @docs ||= begin
      response['docs']
    end
  end

  def spelling
    self['spelling']
  end

  module Response
    def response
      self[:response]
    end
    
    # short cut to response['numFound']
    def total
      response[:numFound].to_s.to_i
    end
    
    def start
      response[:start].to_s.to_i
    end
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
blacklight-4.3.0 lib/blacklight/solr_response.rb
blacklight-4.2.2 lib/blacklight/solr_response.rb
blacklight-4.2.1 lib/blacklight/solr_response.rb
blacklight-4.2.0 lib/blacklight/solr_response.rb
blacklight-4.1.0 lib/blacklight/solr_response.rb