Class: Sunspot::Search::FieldJsonFacet
- Inherits:
-
Object
- Object
- Sunspot::Search::FieldJsonFacet
- Defined in:
- lib/sunspot/search/field_json_facet.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(field, search, options) ⇒ FieldJsonFacet
constructor
A new instance of FieldJsonFacet.
- #no_data? ⇒ Boolean
- #other_count(type) ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(field, search, options) ⇒ FieldJsonFacet
Returns a new instance of FieldJsonFacet.
7 8 9 10 |
# File 'lib/sunspot/search/field_json_facet.rb', line 7 def initialize(field, search, ) @name, @search, @options = ([:name] || field.name), search, @field = field end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/sunspot/search/field_json_facet.rb', line 5 def name @name end |
Instance Method Details
#no_data? ⇒ Boolean
31 32 33 |
# File 'lib/sunspot/search/field_json_facet.rb', line 31 def no_data? @search.json_facet_response[@field.name.to_s].nil? end |
#other_count(type) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/sunspot/search/field_json_facet.rb', line 35 def other_count(type) json_facet_for_field = @search.json_facet_response[@field.name.to_s] return 0 if json_facet_for_field.nil? other = json_facet_for_field[type.to_s] || {} other['count'] end |
#rows ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sunspot/search/field_json_facet.rb', line 12 def rows @rows ||= begin data = no_data? ? [] : @search.json_facet_response[@field.name.to_s]['buckets'] rows = [] data.each do |d| rows << JsonFacetRow.new(d, self) end if @options[:sort] == :count rows.sort! { |lrow, rrow| rrow.count <=> lrow.count } else rows.sort! { |lrow, rrow| lrow.value <=> rrow.value } end rows end end |