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
-
#rows ⇒ Object
Get the rows associated with this query facet.
Methods inherited from Abstract
Constructor Details
#initialize(outgoing_query_facet, row_data) ⇒ QueryFacetData
:nodoc:
102 103 104 105 |
# File 'lib/sunspot/facet_data.rb', line 102 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
107 108 109 |
# File 'lib/sunspot/facet_data.rb', line 107 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/sunspot/facet_data.rb', line 119 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 |