class Blacklight::Solr::Response
Attributes
blacklight_config[RW]
options[RW]
request_params[R]
Public Class Methods
new(data, request_params, options = {})
click to toggle source
Calls superclass method
# 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
Public Instance Methods
documents()
click to toggle source
# File lib/blacklight/solr/response.rb, line 27 def documents @documents ||= (response['docs'] || []).collect { |doc| document_factory.build(doc, self, options) } end
Also aliased as: docs
export_formats()
click to toggle source
# File lib/blacklight/solr/response.rb, line 57 def export_formats documents.map { |x| x.export_formats.keys }.flatten.uniq end
group(key)
click to toggle source
# File lib/blacklight/solr/response.rb, line 49 def group key grouped.find { |x| x.key == key } end
grouped()
click to toggle source
# 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?()
click to toggle source
# File lib/blacklight/solr/response.rb, line 53 def grouped? key? "grouped" end
header()
click to toggle source
# File lib/blacklight/solr/response.rb, line 23 def header self['responseHeader'] || {} end
Private Instance Methods
force_to_utf8(value)
click to toggle source
# File lib/blacklight/solr/response.rb, line 63 def force_to_utf8(value) case value when Hash value.each { |k, v| value[k] = force_to_utf8(v) } when Array value.each { |v| force_to_utf8(v) } when String if value.encoding == Encoding::UTF_8 value else Blacklight.logger&.warn "Found a non utf-8 value in Blacklight::Solr::Response. \"#{value}\" Encoding is #{value.encoding}" value.dup.force_encoding('UTF-8') end end value end