Class: Sunspot::FacetData::QueryFacetData

Inherits:
Abstract
  • Object
show all
Defined in:
lib/sunspot/facet_data.rb

Instance Attribute Summary

Attributes inherited from Abstract

#field

Instance Method Summary collapse

Methods inherited from Abstract

#cast, #reference, #row_value

Constructor Details

#initialize(outgoing_query_facet, row_data) ⇒ QueryFacetData

:nodoc:



88
89
90
91
# File 'lib/sunspot/facet_data.rb', line 88

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

#nameObject



93
94
95
# File 'lib/sunspot/facet_data.rb', line 93

def name
  outgoing_query_facet.name
end

#rowsObject

Get the rows associated with this query facet. Returned rows are always ordered by count.

Returns

Array

Collection of QueryFacetRow objects, ordered by count



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/sunspot/facet_data.rb', line 105

def rows
  @rows ||=
    begin
      rows = []
      for row in  @outgoing_query_facet.rows
        row_query = row.to_boolean_phrase
        if @row_data.has_key?(row_query)
          rows << yield(row.label, @row_data[row_query])
        end
      end
      rows.sort! { |x, y| y.count <=> x.count }
    end
end