Class: Blacklight::Solr::Response::GroupResponse

Inherits:
Object
  • Object
show all
Includes:
PaginationMethods
Defined in:
lib/blacklight/solr/response/group_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PaginationMethods

#limit_value, #offset_value, #size, #total_count

Constructor Details

#initialize(key, group, response) ⇒ GroupResponse

Returns a new instance of GroupResponse.



8
9
10
11
12
# File 'lib/blacklight/solr/response/group_response.rb', line 8

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/blacklight/solr/response/group_response.rb', line 54

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

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'lib/blacklight/solr/response/group_response.rb', line 6

def group
  @group
end

#keyObject (readonly) Also known as: group_field

Returns the value of attribute key.



6
7
8
# File 'lib/blacklight/solr/response/group_response.rb', line 6

def key
  @key
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/blacklight/solr/response/group_response.rb', line 6

def response
  @response
end

Instance Method Details

#empty?Boolean

Relying on a fallback (method missing) to @response is problematic as it will not evaluate the correct ‘total` method.

Returns:

  • (Boolean)


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

def empty?
  total.zero?
end

#entry_name(options) ⇒ Object

Overridden from Blacklight::Solr::Response::PaginationMethods to support grouped key specific i18n keys. ‘key` is the field being grouped



46
47
48
49
50
51
52
# File 'lib/blacklight/solr/response/group_response.rb', line 46

def entry_name(options)
  I18n.t(
    "blacklight.entry_name.grouped.#{key}",
    default: :'blacklight.entry_name.grouped.default',
    count: options[:count]
  )
end

#group_limitObject



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

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

#groupsObject



16
17
18
19
20
# File 'lib/blacklight/solr/response/group_response.rb', line 16

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

#respond_to_missing?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#startObject



32
33
34
# File 'lib/blacklight/solr/response/group_response.rb', line 32

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

#totalObject



26
27
28
29
30
# File 'lib/blacklight/solr/response/group_response.rb', line 26

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