Class: Blacklight::Solr::Response

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

Defined Under Namespace

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

Constant Summary

Constants included from Params

Params::QUERY_PARAMETER_TO_JSON_PARAMETER_MAPPING

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Params

#facet_field_aggregation_options, #params, #rows, #sort, #start

Methods included from MoreLikeThis

#more_like, #more_like_this

Methods included from Response

#empty?, #response, #start, #total

Methods included from Facets

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

Methods included from Spelling

#spelling

Methods included from PaginationMethods

#entry_name, #limit_value, #offset_value, #size, #total_count

Constructor Details

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

Returns a new instance of Response.



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

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

Instance Attribute Details

#blacklight_configObject

Returns the value of attribute blacklight_config.



12
13
14
# File 'lib/blacklight/solr/response.rb', line 12

def blacklight_config
  @blacklight_config
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/blacklight/solr/response.rb', line 12

def options
  @options
end

#request_paramsObject (readonly)

Returns the value of attribute request_params.



11
12
13
# File 'lib/blacklight/solr/response.rb', line 11

def request_params
  @request_params
end

Instance Method Details

#documentsObject Also known as: docs



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

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

#export_formatsObject



57
58
59
# File 'lib/blacklight/solr/response.rb', line 57

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

#group(key) ⇒ Object



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

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

#groupedObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/blacklight/solr/response.rb', line 32

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)


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

def grouped?
  key? "grouped"
end

#headerObject



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

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