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
The complete list of attributes to use for faceting.
Use this setting for two reasons:
- To turn an attribute into a facet. This is a prerequisite for faceted search.
- To make any string attribute filterable.
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.
By default, your index doesn’t have categories. Designating an attribute as a facet enables Algolia to compute a set of possible values that can later be used to filter results or display these categories. You can also get a count of records that match those values.
Usage notes
This setting enables both faceting and filtering.
- Faceting allows you to use attributes inside facets
- Filtering allows you to use attributes inside filters, facetFilters, and optionalFilter
If not specified or empty, no attribute will be faceted.
All attributes can be used for faceting, even when nested. For example, authors.mainAuthor
can be used for faceting. Here the faceting will be applied only on mainAuthor
.
Don’t include colons (:
) in attribute names that you want to use for faceting because the filters
syntax relies on that character as a delimiter.
Modifiers
|
Defines an attribute as filterable only and not facetable. If you only need the filtering feature, use the You can’t define an attribute as |
|
Defines an attribute as searchable. If you want to search for values of a given facet (using the Search for facet values method), use the You can’t define an attribute as |
|
Computes the facet counts of this attribute after If you use the It can be helpful to combine the Note that if you use both the |
Examples
Set attributesForFaceting
The following example shows how to:
- Make some attributes usable for faceting
- Make an attribute only filterable
- Make an attribute usable with
Search for facet values
1
2
3
4
5
6
7
8
9
$index->setSettings([
'attributesForFaceting' => [
"author",
"filterOnly(isbn)",
"searchable(edition)",
"afterDistinct(category)",
"afterDistinct(searchable(publisher))"
]
]);