Class: Sunspot::FacetData::QueryFacetData
- Defined in:
- lib/sunspot/facet_data.rb
Overview
QueryFacetData encapsulates the data returned by a query facet.
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(outgoing_query_facet, row_data) ⇒ QueryFacetData
constructor
:nodoc:.
-
#name ⇒ Object
Use the name defined by the user.
-
#rows ⇒ Object
Get the rows associated with this query facet.
Methods inherited from Abstract
Constructor Details
#initialize(outgoing_query_facet, row_data) ⇒ QueryFacetData
:nodoc:
116 117 118 119 |
# File 'lib/sunspot/facet_data.rb', line 116 def initialize(outgoing_query_facet, row_data) #:nodoc: @outgoing_query_facet, @row_data = outgoing_query_facet, row_data @field = @outgoing_query_facet.field end |
Instance Method Details
#name ⇒ Object
Use the name defined by the user
124 125 126 |
# File 'lib/sunspot/facet_data.rb', line 124 def name outgoing_query_facet.name end |
#rows ⇒ Object
Get the rows associated with this query facet. Returned rows are always ordered by count.
Returns
- Array
-
Collection of QueryFacetRow objects, ordered by count
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/sunspot/facet_data.rb', line 136 def rows @rows ||= begin rows = [] = @outgoing_query_facet. minimum_count = if [:zeros] then 0 elsif [:minimum_count] then [:minimum_count] else 1 end for outgoing_row in @outgoing_query_facet.rows row_query = outgoing_row.to_boolean_phrase if @row_data.has_key?(row_query) row = yield(outgoing_row.label, @row_data[row_query]) rows << row if row.count >= minimum_count end end if [:sort] == :index || ![:limit] && [:sort] != :count if rows.all? { |row| row.value.respond_to?(:<=>) } rows.sort! { |x, y| x.value <=> y.value } end else rows.sort! { |x, y| y.count <=> x.count } end if limit = [:limit] rows[0, limit] else rows end end end |