Class: Ansr::Blacklight::Solr::Response

Inherits:
HashWithIndifferentAccess
  • Object
show all
Includes:
PaginationMethods
Defined in:
lib/ansr_blacklight/solr/response.rb

Overview

copied directly from Blacklight::SolrResponse

Defined Under Namespace

Modules: InternalResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PaginationMethods

#limit_value, #model_name, #next_page, #offset_value, #prev_page, #total_count

Constructor Details

#initialize(data, request_params) ⇒ Response

Returns a new instance of Response.



14
15
16
17
18
19
20
21
# File 'lib/ansr_blacklight/solr/response.rb', line 14

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

Instance Attribute Details

#request_paramsObject (readonly)

Returns the value of attribute request_params.



13
14
15
# File 'lib/ansr_blacklight/solr/response.rb', line 13

def request_params
  @request_params
end

Instance Method Details

#docsObject



40
41
42
43
44
# File 'lib/ansr_blacklight/solr/response.rb', line 40

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

#group(key, model) ⇒ Object



67
68
69
# File 'lib/ansr_blacklight/solr/response.rb', line 67

def group key, model
  grouped(model).select { |x| x.key == key }.first
end

#grouped(model) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ansr_blacklight/solr/response.rb', line 50

def grouped(model)
  @groups ||= self["grouped"].map do |field, group|
    # grouped responses can either be grouped by:
    #   - field, where this key is the field name, and there will be a list
    #        of documents grouped by field value, or:
    #   - function, where the key is the function, and the documents will be
    #        further grouped by function value, or:
    #   - query, where the key is the query, and the matching documents will be
    #        in the doclist on THIS object
    if group["groups"] # field or function
      GroupResponse.new field, model, group, self
    else # query
      Group.new({field => field}, model, group, self)
    end
  end
end

#grouped?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/ansr_blacklight/solr/response.rb', line 71

def grouped?
  self.has_key? "grouped"
end

#headerObject



23
24
25
# File 'lib/ansr_blacklight/solr/response.rb', line 23

def header
  self['responseHeader']
end

#paramsObject



32
33
34
# File 'lib/ansr_blacklight/solr/response.rb', line 32

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

#rowsObject



36
37
38
# File 'lib/ansr_blacklight/solr/response.rb', line 36

def rows
    params[:rows].to_i
end

#spellingObject



46
47
48
# File 'lib/ansr_blacklight/solr/response.rb', line 46

def spelling
  self['spelling']
end

#update(other_hash) ⇒ Object



27
28
29
30
# File 'lib/ansr_blacklight/solr/response.rb', line 27

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