Category facet sub-controller
Category facet sub-controller
|
|
Note
This component was introduced in version |
Create facet sub-controllers using FacetGenerator sub-controller of the Search controller.
const searchController = buildSearch(commerceEngine);
const facetGenerator = searchController.facetGenerator();
for (const facet of facetGenerator.facets) {
switch (facet.type) {
case 'regular':
// facet will be typed as RegularFacet, render it...
break;
case 'dateRange':
// facet will be typed as DateFacet, render it...
break;
case 'numericalRange':
// facet will be typed as NumericFacet, render it...
break;
case 'hierarchical':
// facet will be typed as CategoryFacet, render it...
}
}
Methods
deselectAll
Deselects all facet values.
isValueSelected
Checks whether the specified facet value is selected.
Parameters
-
value:
CategoryFacetValueThe facet value to check.
Returns boolean: Whether the specified facet value is selected.
showLessValues
Sets the number of values displayed in the facet to the originally configured value.
showMoreValues
Increases the number of values displayed in the facet to the next multiple of the originally configured value.
toggleSelect
Toggles the specified facet value.
Parameters
-
selection:
CategoryFacetValueThe facet value to toggle.
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => voidA callback that’s invoked on state change.
Returns Unsubscribe: A function to remove the listener.
Attributes
type
The type of the facet.
facetSearch
Provides methods to search the facet’s values.
Methods
clear
Resets the query and empties the values.
search
Performs a facet search.
select
Selects a facet search result.
Parameters
-
value:
SpecificFacetSearchResultThe search result to select.
updateText
Updates the facet search query.
Parameters
-
text:
stringThe query to search.
state
The state of the Facet controller.
Properties
-
type:
'regular' | 'dateRange' | 'numericalRange' | 'hierarchical'The type of the facet.
-
facetSearch:
FacetSearchStateThe state of the facet’s searchbox.
-
canShowLessValues:
booleantrueif fewer values can be displayed andfalseotherwise. -
canShowMoreValues:
booleantrueif there are more values to display andfalseotherwise. -
facetId:
stringThe facet ID.
-
hasActiveValues:
booleantrueif there is at least one non-idle value andfalseotherwise. -
isLoading:
booleantrueif a search is in progress andfalseotherwise. -
values:
CategoryFacetValue[]The values of the facet.
-
field:
stringThe facet field.
-
displayName?:
stringThe facet name.
-
activeValue?:
CategoryFacetValueThe currently active value in the category facet.
-
selectedValueAncestry?:
CategoryFacetValue[]An array of the selected values in the ancestry of the category facet.
-
facetSearch:
CategoryFacetSearchStateThe state of the category facet’s search box.
Related types
CategoryFacetValue
Properties
-
numberOfResults:
numberThe number of results that have the facet value.
-
state:
'idle' | 'selected' | 'excluded'Whether a facet value is filtering results (
selected) or not (idle). -
value:
stringThe facet value.
SpecificFacetSearchResult
Properties
-
count:
numberAn estimate of the number of result items matching both the current query and the filter expression that would get generated if the facet value were selected.
-
displayValue:
stringThe custom facet value display name.
-
rawValue:
stringThe original facet value, as retrieved from the field in the index.
CategoryFacetSearchState
Properties
-
isLoading:
booleanReturns
trueif the facet search is in progress, andfalseif not. -
moreValuesAvailable:
booleanWhether more values are available.
-
query:
stringThe current query in the facet search box.
-
values:
CategoryFacetSearchResult[]The facet search results.
CategoryFacetSearchResult
Properties
-
count:
numberAn estimate of the number of result items that match both the current query and the filter expression which would be generated if the facet value were selected.
-
displayValue:
stringThe custom facet value display name.
-
path:
string[]The hierarchical path to the facet value.
-
rawValue:
stringThe original facet value, as retrieved from the field in the index.
Unsubscribe
Call signatures
-
(): void;