Class: Blacklight::Solr::Response::GroupResponse
- Inherits:
-
Object
- Object
- Blacklight::Solr::Response::GroupResponse
- Includes:
- PaginationMethods
- Defined in:
- lib/blacklight/solr/response/group_response.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#key ⇒ Object
(also: #group_field)
readonly
Returns the value of attribute key.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Relying on a fallback (method missing) to @response is problematic as it will not evaluate the correct ‘total` method.
-
#entry_name(options) ⇒ Object
Overridden from Blacklight::Solr::Response::PaginationMethods to support grouped key specific i18n keys.
- #group_limit ⇒ Object
- #groups ⇒ Object
-
#initialize(key, group, response) ⇒ GroupResponse
constructor
A new instance of GroupResponse.
- #method_missing(meth, *args, &block) ⇒ Object
- #respond_to_missing?(meth, include_private = false) ⇒ Boolean
- #start ⇒ Object
- #total ⇒ Object
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
#group ⇒ Object (readonly)
Returns the value of attribute group.
6 7 8 |
# File 'lib/blacklight/solr/response/group_response.rb', line 6 def group @group end |
#key ⇒ Object (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 |
#response ⇒ Object (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.
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() I18n.t( "blacklight.entry_name.grouped.#{key}", default: :'blacklight.entry_name.grouped.default', count: [:count] ) end |
#group_limit ⇒ Object
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 |
#groups ⇒ Object
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
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 |
#start ⇒ Object
32 33 34 |
# File 'lib/blacklight/solr/response/group_response.rb', line 32 def start params[:start].to_s.to_i end |
#total ⇒ Object
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 |