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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, model, group, response) ⇒ GroupResponse

Returns a new instance of GroupResponse.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



36
37
38
39
40
41
42
43
44
# File 'lib/ansr_blacklight/solr/response/group_response.rb', line 36

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.



5
6
7
# File 'lib/ansr_blacklight/solr/response/group_response.rb', line 5

def group
  @group
end

#keyObject (readonly) Also known as: group_field

Returns the value of attribute key.



5
6
7
# File 'lib/ansr_blacklight/solr/response/group_response.rb', line 5

def key
  @key
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/ansr_blacklight/solr/response/group_response.rb', line 5

def model
  @model
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/ansr_blacklight/solr/response/group_response.rb', line 5

def response
  @response
end

Instance Method Details

#group_limitObject



22
23
24
# File 'lib/ansr_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/ansr_blacklight/solr/response/group_response.rb', line 16

def groups
  @groups ||= group["groups"].map do |g|
    Ansr::Blacklight::Solr::Response::Group.new({key => g[:groupValue]}, model, g, self)
  end
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ansr_blacklight/solr/response/group_response.rb', line 46

def respond_to? meth
  response.respond_to?(meth) || super
end

#startObject



32
33
34
# File 'lib/ansr_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/ansr_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.facet_by_field_name(key) || []).length).to_s.to_i
end