attributesForFaceting
'attributesForFaceting' => [ 'attribute1', 'filterOnly(attribute2)', 'searchable(attribute3)', 'afterDistinct(attribute4)', 'afterDistinct(searchable(attribute5))' ]
Can be used in these methods:
setSettings
set_settings
setSettings
set_settings
setSettings
setSettings
SetSettings
setSettings
SetSettings
setSettings
About this parameter
List of attributes to use for faceting.
Algolia lets you create categories based on specific attributes so users can filter search results by those categories. For example, if you have an index of books, you could categorize them by author and genre. This allows users to filter search results by their favorite author or discover new genres.
To enable this categorization, declare your attributes as attributesForFaceting
.
There’s no limit to the number of attributes in the list, but having many attributes slows down calls to getSettings
. This can make the Algolia dashboard slower and less responsive.
Usage notes
If no attribute is specified, no attributes will be faceted.
Specify an attribute with attributesForFaceting
to enable faceting and filtering:
- Faceting allows you to use attributes inside facets
- Filtering allows you to use attributes inside
filters
,facetFilters
, andoptionalFilters
All attributes can be used for faceting, even when nested.
For example, authors.mainAuthor
can be used for faceting but will only be applied on mainAuthor
.
Don’t use colons (:
) in attribute names you want to use for faceting because the filters
syntax relies on that character as a delimiter.
Use modifiers to change the behavior of faceted attributes. If you don’t specify a modifier, an attribute will just be used as a facet. This is the equivalent of setting an attribute as not searchable on the dashboard.
Modifiers
|
Only define this modifier if you want to use an attribute for filtering (not faceting). This modifier reduces index size and improves search speed. You can’t define an attribute as |
|
Only define this modifier if you want users to search for facet values. It can be helpful to combine the You can’t define an attribute as |
|
Computes the facet counts of an attribue after If you’re using If you use the It can be helpful to combine the |
Examples
Set attributesForFaceting
The following example shows how to:
- Define some attributes as usable for faceting:
author
,edition
,category
, andpublisher
- Set the
isbn
attribute as only usable for filtering - Allow the
edition
andpublisher
facet values to be searchable.
1
2
3
4
5
6
7
8
9
$index->setSettings([
'attributesForFaceting' => [
"author",
"filterOnly(isbn)",
"searchable(edition)",
"afterDistinct(category)",
"afterDistinct(searchable(publisher))"
]
]);