Facets are search filters that allow users to refine the list of products they see based on criteria such as size, price, brand and other product attributes.
At the technical level, a facet is a mapping between a control - e.g. a checkbox list - and a query parameter. When a frontend user does something with a control - checks a box, moves a slider - a value is passed from frontend back to the query which then reevaluates which content to return.
Facets on values with commas, slashes, and other URL-unsafe characters
Sometimes you want to match field values using facets even if they contain "odd" characters such as:
- commas (e.g.
1,5) - slashes (e.g.
2/7) - whitespace (e.g.
my value) - mixed formats (e.g.
5,5/7,5)
This is often necessary when the data represents e.g. effect values, classifications, codes, labels, or locale-dependent numeric strings.
To properly match these types of values you must create the following types of index fields:
- Field type: String
- Analysis: Not analyzed
- Example: Effect_NotAnalyzed
Furthermore, the query parameter for matching these types of values must be String[] - which is to say an array, the operator must be In, and in the URL syntax you must wrap all values in square brackets:
&Effect=[11],[2,2]
Here are some examples which illustrate how each bracketed segment is treated as an atomic string value:
&Effect=[1]
&Effect=[1,5]
&Effect=[2/7]
&Effect=[5,5/7,5]
&Effect=[my value]
You can also match multiple values using this approach:
&Effect=[1],[1,5],[2/7]