Class: Blacklight::Solr::Response

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Extended by:
Deprecation
Includes:
Facets, MoreLikeThis, PaginationMethods, Response, Spelling
Defined in:
lib/blacklight/solr/response.rb

Defined Under Namespace

Modules: Facets, MoreLikeThis, PaginationMethods, Response, Spelling Classes: Group, GroupResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MoreLikeThis

#more_like, #more_like_this

Methods included from Response

#empty?, #response, #total

Methods included from Facets

#aggregations, #facet_counts, #facet_fields, #facet_pivot, #facet_queries

Methods included from Spelling

#spelling

Methods included from PaginationMethods

#limit_value, #offset_value, #total_count

Constructor Details

#initialize(data, request_params, options = {}) ⇒ Response

Returns a new instance of Response.



25
26
27
28
29
30
# File 'lib/blacklight/solr/response.rb', line 25

def initialize(data, request_params, options = {})
  super(force_to_utf8(ActiveSupport::HashWithIndifferentAccess.new(data)))
  @request_params = ActiveSupport::HashWithIndifferentAccess.new(request_params)
  self.document_model = options[:solr_document_model] || options[:document_model] || SolrDocument
  self.blacklight_config = options[:blacklight_config]
end

Instance Attribute Details

#blacklight_configObject

Returns the value of attribute blacklight_config.



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

def blacklight_config
  @blacklight_config
end

#document_modelObject

Returns the value of attribute document_model.



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

def document_model
  @document_model
end

#request_paramsObject (readonly)

Returns the value of attribute request_params.



22
23
24
# File 'lib/blacklight/solr/response.rb', line 22

def request_params
  @request_params
end

Instance Method Details

#documentsObject Also known as: docs



52
53
54
# File 'lib/blacklight/solr/response.rb', line 52

def documents
  @documents ||= (response['docs'] || []).collect{|doc| document_model.new(doc, self) }
end

#export_formatsObject



82
83
84
# File 'lib/blacklight/solr/response.rb', line 82

def export_formats
  documents.map { |x| x.export_formats.keys }.flatten.uniq
end

#group(key) ⇒ Object



74
75
76
# File 'lib/blacklight/solr/response.rb', line 74

def group key
  grouped.find { |x| x.key == key }
end

#groupedObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/blacklight/solr/response.rb', line 57

def grouped
  @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, group, self
    else # query
      Group.new field, group, self
    end
  end
end

#grouped?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/blacklight/solr/response.rb', line 78

def grouped?
  self.key? "grouped"
end

#headerObject



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

def header
  self['responseHeader'] || {}
end

#paramsObject



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

def params
  header['params'] || request_params
end

#rowsObject



44
45
46
# File 'lib/blacklight/solr/response.rb', line 44

def rows
  params[:rows].to_i
end

#sortObject



48
49
50
# File 'lib/blacklight/solr/response.rb', line 48

def sort
  params[:sort]
end

#startObject



40
41
42
# File 'lib/blacklight/solr/response.rb', line 40

def start
  params[:start].to_i
end