Sha256: 732642b41faaf4dfcfe7729a1f03475997220b20f71fbf8e75a73e07f3ef0209

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true
class Blacklight::Solr::Response::GroupResponse
  include Blacklight::Solr::Response::PaginationMethods

  attr_reader :key, :group, :response

  def initialize key, group, response
    @key = key
    @group = group
    @response = response
  end

  alias_method :group_field, :key

  def groups
    @groups ||= group["groups"].map do |g|
      Blacklight::Solr::Response::Group.new g[:groupValue], g, self
    end
  end

  def group_limit
    params.fetch(:'group.limit', 1).to_s.to_i
  end

  def total
    # ngroups is only available in Solr 4.1+
    # fall back on the number of facet items for that field?
    (group["ngroups"] || (response.aggregations[key] || []).length).to_s.to_i
  end

  def start
    params[:start].to_s.to_i
  end

  ##
  # Relying on a fallback (method missing) to @response is problematic as it
  # will not evaluate the correct `total` method.
  def empty?
    total.zero?
  end

  def method_missing meth, *args, &block
    if response.respond_to? meth
      response.send(meth, *args, &block)
    else
      super
    end
  end

  def respond_to_missing? meth, include_private = false
    response.respond_to?(meth) || super
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
blacklight-7.1.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.1.0.alpha lib/blacklight/solr/response/group_response.rb
blacklight-7.0.1 lib/blacklight/solr/response/group_response.rb
blacklight-7.0.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.0.0.rc2 lib/blacklight/solr/response/group_response.rb
blacklight-7.0.0.rc1 lib/blacklight/solr/response/group_response.rb