What is a facet anyway? The word appears in many places across the Algolia landscape, and in different contexts. Here we'll seek to explain what it means and some of the different settings that feature the name.
- A facet is a way to identify a feature of a record that may be shared among a larger number of records. A good example would be "Brand."
- A facet value is the specific attribute information unique to a record. So if "Brand" is the facet, then "Apple" could be the facet value on certain records.
- Facets can be searchable, or non-searchable.
The image above shows the facet "Brand," along with several different facet values, and a magnifying glass indicating this facet is searchable. The below image includes an example search for facet values (different from a normal search query):
When searching for facet values, the parameter maxFacetHits determines the number of possible values that can be returned. Note that this parameter is specific to facet value searches, not normal searches.
In the above example there are 3 values returned. There won't be more than 10 values returned, because the maxFacetHits parameter is set to 10 on that index (which is the default):
This parameter can be set to a maximum of 100 facet values:
https://www.algolia.com/doc/api-reference/api-parameters/maxFacetHits/
We also have the parameter maxValuesPerFacet, which is different from maxFacetHits. This parameter determines the maximum number of facet values that can be returned in a normal search query. It is set to 100 by default.
So for example, if I search for "phone" as a normal query on an e-commerce site, and there are 143 different brands of phone in the index, it is only going to show me the top 100 brands. For example, there are 100 total facet values displaying below (5+95=100):
This parameter can be set to a maximum of 1000 facet values:
Neither of these parameters determine the total number of attributes that may be used for faceting during a normal search. This is simply equal to the number of attributesForFaceting that you have declared.
https://www.algolia.com/doc/api-reference/api-parameters/attributesForFaceting/
If you are using InstantSearch, all relevant facets should be returned with each query. If you are not using InstantSearch, facet information can be retrieved with the "facet" parameter during a normal search query:
https://www.algolia.com/doc/api-reference/api-parameters/facets/
You can extract all facet information using a wildcard (*). Bear in mind that this only applies to the records present in the query results.
https://www.algolia.com/doc/guides/managing-results/refine-results/faceting/#retrieving-facets