module RSolr::Response
def self.included(base)
def self.included(base) unless base < Hash raise ArgumentError, "RSolr::Response expects to included only in (sub)classes of Hash; got included in '#{base}' instead." end base.send(:attr_reader, :request, :response) end
def initialize_rsolr_response(request, response, result)
def initialize_rsolr_response(request, response, result) @request = request @response = response self.merge!(result) if self["response"] && self["response"]["docs"].is_a?(Array) docs = PaginatedDocSet.new(self["response"]["docs"]) docs.per_page = request[:params]["rows"] docs.page_start = request[:params]["start"] docs.page_total = self["response"]["numFound"].to_s.to_i self["response"]["docs"] = docs end end
def with_indifferent_access
def with_indifferent_access if defined?(::RSolr::HashWithIndifferentAccessWithResponse) ::RSolr::HashWithIndifferentAccessWithResponse.new(request, response, self) else if defined?(ActiveSupport::HashWithIndifferentAccess) RSolr.const_set("HashWithIndifferentAccessWithResponse", Class.new(ActiveSupport::HashWithIndifferentAccess)) RSolr::HashWithIndifferentAccessWithResponse.class_eval <<-eos include RSolr::Response def initialize(request, response, result) super() initialize_rsolr_response(request, response, result) end eos ::RSolr::HashWithIndifferentAccessWithResponse.new(request, response, self) else raise RuntimeError, "HashWithIndifferentAccess is not currently defined" end end end