1. Query

Facets

In Sitecore Search, you can use facets to classify your content. Facet values can be a string, a number, or a range. Often facets are displayed in the UI as part of the search experience.

To narrow results in a search results widget, you need to include the facets model or SearchResultsConfig and values for selected facets or array of SearchResultsStoreSelectedFacet.

SearchResultsConfig and facets

This object describes configuration for the search request and results, and is included in the useSearchResults query hook. You need to include a SearchResultsFacetConfigItem object in its facets value to configure how the facet is handled. By default, facets are compared using valueId.

PropertyTypeDescription
facetsSearchResultsStoreSelectedFacetsObject of key-value pairs where the keys are the facet name and the values are SearchResultsFacetConfigItem objects.
Note

Refer to the Sitecore Search interface for attribute names.

SearchResultsFacetConfigItem

PropertyTypeDescriptionValues
typeFacetPayloadTypeRequired.

Describes the type of payload.
Default: valueId

text

rage

SearchResultsStoreSelectedFacet

The state object in useSearchResults contains the selectedFacets attribute, which is an array of SearchResultsStoreSelectedFacet objects that include SearchResultsStoreValueIdSelectedFacet, SearchResultsStoreRangeSelectedFacet, and SearchResultsStoreTextSelectedFacet.

SearchResultsStoreTextSelectedFacet

Extends BaseSearchResultsStoreSelectedFacet

PropertyTypeDescription
facetValueTextstringRequired.

Text associated with the facet.
facetValueIdstringID associated with the facet value.

SearchResultsStoreValueIdSelectedFacet

Extends BaseSearchResultsStoreSelectedFacet

PropertyTypeDescription
facetValueIdstringRequired.

ID associated with the facet value.

SearchResultsStoreRangeSelectedFacet

Extends BaseSearchResultsStoreSelectedFacet

PropertyTypeDescription
minnumberMinimum facet value.
maxnumberMaximum facet value.

BaseSearchResultsStoreSelectedFacet

This is the base type for selected facet objects.

PropertyTypeDescription
facetIdnumberRequired.

ID associated with the facet.
facetLabelstringDisplay label associated with facet.
valueLabelstringDisplay label associated with facet value.
If you have suggestions for improving this article, let us know!