API Reference / API Parameters / sortFacetValuesBy
Feb. 26, 2019

sortFacetValuesBy

Type: string
Engine default: count
Parameter syntax
'sortFacetValuesBy' => 'count'|'alpha'

Can be used in these methods:

About this parameter

Controls how facet values are sorted.

When using facets, Algolia retrieves a list of matching facet values for each faceted attribute. This parameter controls how the facet values are sorted within each faceted attribute.

Usage notes:

  • You can either sort by count (the default, from high to low) or alphabetically

  • The set of returned facet values depends on the maximum number of facet values returned, which depends on the maxValuesPerFacet setting. The default is 100 and the max is 1000. Therefore, values with very low frequency could potentially not be returned.

Options:

  • count: Facet values are sorted by decreasing count. The count is the number of records containing this facet value in the results of the query.

  • alpha: Facet values are sorted in alphabetical order, ascending from A to Z.

Examples

Set default sort order for facet values

1
2
3
$index->setSettings([
  'sortFacetValuesBy': 'alpha'
]);

Override default sort order for facet values at query time

1
2
3
$results = $index->search('query', [
  'sortFacetValuesBy' => "count"
]);

Did you find this page helpful?