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

# 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