Regular facet sub-controller
Regular facet sub-controller
This is for:
DeveloperCreate 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.
isValueExcluded
Checks whether the specified facet value is excluded.
Parameters
-
value:
RegularFacetValue
The facet value to check.
Returns boolean
: Whether the specified facet value is excluded.
isValueSelected
Checks whether the specified facet value is selected.
Parameters
-
value:
RegularFacetValue
The 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.
toggleExclude
Toggles exclusion of the specified facet value.
Parameters
-
selection:
RegularFacetValue
The facet value to toggle exclusion.
toggleSelect
Toggles the specified facet value.
Parameters
-
selection:
RegularFacetValue
The facet value to toggle.
toggleSingleExclude
Excludes the specified facet value, deselecting others.
Parameters
-
selection:
RegularFacetValue
The facet value to toggle exclusion.
toggleSingleSelect
Toggles the specified facet value, deselecting others.
Parameters
-
selection:
RegularFacetValue
The facet value to toggle.
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => void
A callback that’s invoked on state change.
Returns Unsubscribe
: A function to remove the listener.
Attributes
facetSearch
Provides methods to search the facet’s values.
Methods
clear
Resets the query and empties the values.
exclude
Excludes a facet search result.
Parameters
-
value:
SpecificFacetSearchResult
The search result to exclude.
search
Performs a facet search.
select
Selects a facet search result.
Parameters
-
value:
SpecificFacetSearchResult
The search result to select.
singleExclude
Excludes a search result while including facet values.
Parameters
-
value:
SpecificFacetSearchResult
The search result to exclude.
singleSelect
Selects a search result while deselecting facet values.
Parameters
-
value:
SpecificFacetSearchResult
The search result to select.
Parameters
-
captions:
Record<string, string>
A dictionary that maps index field values to facet value display names.
updateText
Updates the facet search query.
Parameters
-
text:
string
The query to search.
type
The type of the facet.
state
The state of the Facet
controller.
Properties
-
type:
'regular' | 'dateRange' | 'numericalRange' | 'hierarchical'
The type of the facet.
-
facetSearch:
FacetSearchState
The state of the facet’s searchbox.
-
canShowLessValues:
boolean
true
if fewer values can be displayed andfalse
otherwise. -
canShowMoreValues:
boolean
true
if there are more values to display andfalse
otherwise. -
facetId:
string
The facet ID.
-
hasActiveValues:
boolean
true
if there is at least one non-idle value andfalse
otherwise. -
isLoading:
boolean
true
if a search is in progress andfalse
otherwise. -
values:
RegularFacetValue[]
The values of the facet.
-
field:
string
The facet field.
-
displayName?:
string
The facet name.
Related Types
RegularFacetValue
Properties
-
numberOfResults:
number
The number of results that have the facet value.
-
state:
'idle' | 'selected' | 'excluded'
Whether a facet value is filtering results (
selected
) or not (idle
). -
value:
string
The facet value.
FacetSearchState
Properties
-
query:
string
The facet search query.
-
isLoading:
boolean
Whether the facet search request is in a pending state.
-
values:
SpecificFacetSearchResult[]
The facet values that match the facet search query.
-
moreValuesAvailable:
boolean
Whether additional values matching the facet search query are available.
SpecificFacetSearchResult
Properties
-
count:
number
An 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:
string
The custom facet value display name.
-
rawValue:
string
The original facet value, as retrieved from the field in the index.
Unsubscribe
Call signatures
-
(): void;