class Sunspot::Search::FieldFacet
A FieldFacet
is a facet whose rows are all values for a certain field, in contrast to a QueryFacet
, whose rows represent arbitrary queries.
Public Instance Methods
field_name()
click to toggle source
# File lib/sunspot/search/field_facet.rb, line 13 def field_name @field.name end
rows(options = {})
click to toggle source
Get the rows returned for this facet.
Options (options)¶ ↑
- :verify
-
Only return rows for which the referenced object exists in the data store. This option is ignored unless the field associated with this facet is configured with a :references argument.
Returns¶ ↑
- Array
-
Array of
FacetRow
objects
Calls superclass method
# File lib/sunspot/search/field_facet.rb, line 31 def rows(options = {}) if options[:verify] verified_rows else @rows ||= begin rows = super has_query_facets = !rows.empty? if @search.facet_response['facet_fields'] if data = @search.facet_response['facet_fields'][key] data.each_slice(2) do |value, count| row = FacetRow.new(@field.cast(value), count, self) rows << row end end end sort_rows!(rows) if has_query_facets rows end end end
Private Instance Methods
key()
click to toggle source
# File lib/sunspot/search/field_facet.rb, line 83 def key @key ||= (@options[:name] || @field.indexed_name).to_s end
verified_rows()
click to toggle source
# File lib/sunspot/search/field_facet.rb, line 75 def verified_rows if @field.reference @verified_rows ||= rows.select { |row| row.instance } else rows end end