Sha256: 38937f061330730e7e78957f4dafb7a21e5e0ccb1e51a8a78688e3825e63320a

Contents?: true

Size: 1.5 KB

Versions: 36

Compression:

Stored size: 1.5 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

  ##
  # Overridden from Blacklight::Solr::Response::PaginationMethods to support
  # grouped key specific i18n keys. `key` is the field being grouped
  def entry_name(options)
    I18n.t(
      "blacklight.entry_name.grouped.#{key}",
      default: :'blacklight.entry_name.grouped.default',
      count: options[:count]
    )
  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

36 entries across 36 versions & 2 rubygems

Version Path
blacklight-7.40.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.39.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.38.0 lib/blacklight/solr/response/group_response.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/lib/blacklight/solr/response/group_response.rb
blacklight-7.37.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.36.2 lib/blacklight/solr/response/group_response.rb
blacklight-7.36.1 lib/blacklight/solr/response/group_response.rb
blacklight-7.36.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.35.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.34.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.33.1 lib/blacklight/solr/response/group_response.rb
blacklight-7.33.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.32.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.31.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.30.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.29.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.28.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.27.1 lib/blacklight/solr/response/group_response.rb
blacklight-7.27.0 lib/blacklight/solr/response/group_response.rb
blacklight-7.26.1 lib/blacklight/solr/response/group_response.rb