Class: Blacklight::Solr::Response

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Extended by:
ActiveSupport::Autoload
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.



28
29
30
31
32
33
# File 'lib/blacklight/solr/response.rb', line 28

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.



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

def blacklight_config
  @blacklight_config
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#request_paramsObject (readonly)

Returns the value of attribute request_params.



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

def request_params
  @request_params
end

Instance Method Details

#documentsObject Also known as: docs



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

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

#export_formatsObject



69
70
71
# File 'lib/blacklight/solr/response.rb', line 69

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

#group(key) ⇒ Object



61
62
63
# File 'lib/blacklight/solr/response.rb', line 61

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

#groupedObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/blacklight/solr/response.rb', line 44

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)


65
66
67
# File 'lib/blacklight/solr/response.rb', line 65

def grouped?
  key? "grouped"
end

#headerObject



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

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