Searchkit provides the functionality to add conditions to when to show facets.
Examples of usecases:
- I want to show "CPU Socket type" facets when the customer has selected to filter by "motherboards"
- I want to show different filters depending on the user's role and authorization groups.
The advantages being able to customise the experience around what the customer is filtering for and who they are. Reducing the number of facets also has performance benefits meaning searches will be faster.
You can achieve this by using
VisibleWhen and using the out the box ruleset or building your own custom visibility rules.
VisibleWhen will return these facets only when certain conditions are met.
In this example, on the initial query only the type facet will be returned in the response. When you add a type filter with the value of "Movie", Searchkit API will return you all four facets.
If a writer filter was also added and the type filter was removed, Searchkit API will ignore the writer filter. Applying the filter will have no affect to the search.
The filters that have been applied and disabled will appear in the summary type under
Example where for the above config, writers filters will appear in the disabledFilters array and will be ignored by searchkit.
Rule which is satisfied when a filter has been applied to the search. Facet Identifier is required, value is optional.
You can build a customrule for your usecase. Two important arguments are:
queryManagerwhich you will be able to access the query & filters applied to the search.
ctxwhich is the GraphQL context, normally used to store information about the request.