facets
'facets' => [ 'attribute', ... ]
Can be used in these methods:
search,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
searchForFacetValues
search,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
searchAsync,
searchForFacetValues
Search,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
search into facet values,
generateSecuredApiKey,
add key,
update key
About this parameter
Facets to retrieve.
The effect of this setting: For each of the retrieved facets (eg. color; size), the response will contain a list of facet values (blue, red; small, large, …) in objects matching the current query. Each value will be returned with its associated count (number of matched objects containing that value).
The maximum number of facet values returned depends on the maxValuesPerFacet
setting. The
default is 100 and the max is 1000.
By default, the returned values are sorted by frequency, but this can be changed to alphabetical
with sortFacetValuesBy
.
Usage notes:
-
Facets must have been declared beforehand in the attributesForFaceting index setting.
-
Faceting does not filter your results. If you want to filter results, you should use filters.
-
Default/Empty list: If not specified or empty, no facets are retrieved. The special value
*
may be used to retrieve all facets. -
Approximating facet counts: If the number of hits is high, facet counts may be approximate. The response field
exhaustiveFacetsCount
is true when the count is exact.
Examples
Only retrieve faceting data for some attributes
For this example, let’s consider that attributesForFaceting
are set to:
["category", "author", "nb_views", "nb_downloads"]
but, for the current search, you want to retrieve facet values only for category
and author
.
1
2
3
$results = $index->search('query', [
'facets' => ['category', 'author']
]);