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
Attributes to use for facets.
During index creation, you chose attributes to help users filter and facet search results.
Faceting lets you display categories or counts of values in the UI,
while filtering restricts which records are shown based on specific attribute values.
For example, in a book index, typical faceting attributes include author and genre.
To enable an attribute for filtering or showing as a facet in results,
you must add it to attributesForFaceting.
Usage notes
If no attribute is specified, no attributes will be faceted.
Specify an attribute with attributesForFaceting to enable faceting and filtering:
- Faceting lets you use attributes in facets
- Filtering lets you use attributes in
filters,facetFilters, andoptionalFilters
You can use any attribute for faceting, even if it’s nested.
For example, you can facet on a nested attribute like authors.mainAuthor.
This will only apply the faceting logic to the mainAuthor nested attribute,
not the entire authors attribute.
Attribute names are case-sensitive.
Don’t use colons (:) in attribute names used for faceting.
Colons are reserved for Algolia’s filters syntax.
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 equivalent to setting an attribute as not searchable in the dashboard.
While there’s no limit to the number of attributes, adding too many attributes can slow down calls to getSettings
and reduce the responsiveness of Algolia’s dashboard.
Modifiers
|
Use this modifier if you want to use an attribute for filtering (not faceting).
For example, use it for attributes like This saves space in your index and improves performance. You can’t combine |
|
Use this modifier if you want users to search within a facet’s values. For example, typing a name in a long list of authors. It can be helpful to combine the You can’t combine |
|
Use this modifier when you’ve enabled Only use this on attributes common across all records with the same If you also set It can be helpful to combine the |
Examples
Set attributesForFaceting
In the following example:
1
2
3
4
5
6
7
8
9
10
11
{
"attributesForFaceting": [
"author",
"edition",
"category",
"publisher",
"filterOnly(isbn)",
"searchable(edition)",
"searchable(publisher)"
]
}
author,edition,category, andpublisher: available for both faceting and filtering.isbn: only available for filtering.editionandpublisher: users can search inside these facet values.
1
2
3
4
5
6
7
8
9
$index->setSettings([
'attributesForFaceting' => [
"author",
"filterOnly(isbn)",
"searchable(edition)",
"afterDistinct(category)",
"afterDistinct(searchable(publisher))"
]
]);