Filters
When searching from a PLP, filters are a vital part to enable users to narrow down what they are looking for. For filters to take effect, they must first be added as allowed filters. Ecommerce Search has two different filter types: term filters and range filters.
Term filter
A term filter takes a key and a list of terms, and a match
value to determine how the filter should operate. Currently, allowed match types are: Any
requiring any of the filter values to be present on a product, All
requiring all of the filter values to be present on a product, and None
requiring none of the filter values to be present on the product.
If the match type is not specified in a search request with a term filter, Any
will be used by default.
Filter for either blue or white | |
---|---|
Filter for both waterproof and wind-resistant | |
---|---|
Range filter
A range filter takes a key and specifies a from
and a to
, it then filters products within this range. Either from
or to
can be left out, to filter unbounded.
Only one match type, Within
, currently exists for range filters, including everything within the specified range. If the match type is not specified in a search request with a range filter, Within
will be used by default.
Filter based on an attribute being within a certain range | |
---|---|
Missing Fields
Missing field behavior specifies how the search API handles documents that are missing certain fields when performing searches. This is beneficial when using Unified Search, which returns both products and content which do not share all fields. For example, content does not have a stock or price field, but products do.
When defining a filter you can populate the missing field behavior field. The default behavior is ignoring the document.
Option | Behavior |
---|---|
MatchDocument | Documents with missing fields will be included regardless of filter value. |
IgnoreDocument | Documents with missing fields will be filtered away. |
Using MissingFieldBehavior on domain filter
When searching with a domain filter on price
, with MissingFieldBehavior set to MatchDocument
, ECS will return both content and products. With MissingFieldBehavior set to IgnoreDocument
only the products will be returned as the content doesn't have the price field.
Facets
Facets are filters which allow users to narrow down search results based on specific attributes on products, SKUs or content. These attributes can be anything from color, price, brand, size, etc.
Facets must be created on a context before they can be used. Creating facets has several steps:
- Ingest products with attributes
- Add the field you want to use for the facet as an allowed filter
- Add the field as a context facet on a given context
- Do a search that resolves to that context
Given a context with Color
and Price
as Context facets
and the following search request:
Ecommerce Search returns the following facets.
It shows two facets; color and price. Each facet contains a key
, which represents the attribute name, a facetType
which specifies the type, either a Term or a Range. There is also the name, that is the display name of the facet.
The values
, min
, and max
are values denoting the possible values in the dataset. In this case, it means that if a color filter is applied, the minimum and maximum price will change to the actual minimum and maximum price of the products with that color.
Term facets contain a list of values, listing all possible values for the given key. It also specifies if the facets are selected or not, and which specific values from the facet that has been selected.
Range facets contain min
and max
which specifies the range of values of the products. It also shows the selected from
and to
.
Note
When resolving context facets, both the filter key, e.g. Color
, and the match type, default Any
for term filters and Within
for range filters, must match. If a filter in a search request does not match any context facets, it will not function as a facet, but as a domain filter.
Example
Request | |
---|---|
Facets & Missing Field Behavior
Documents with missing fields are not counted towards facets.
Domain filters
A domain filter can be applied even if it is not a facet. This will ensure a more accurate and specific calculation of facets. Content and products that are excluded by a domain filter will not be included in the calculation of Total hits
, and will not be used in the calculation of facets.
Domain filters are not intended for end-users to apply themselves, but instead are determined by their scope and credentials.
Domain filters cover the following filter types:
- Domain filters specified on a scope
- Filters applied to Authencicated Search
- Filters applied by the client
Using domain filters
A commonly used domain filter could be CategoryIds
, which might be pre-applied when searching from certain pages on your ecommerce site.
Filters can be represented by the following diagram:
Filtering on predefined fields
Ecommerce Search has some predefined fields on content and products/SKUs. The following table provides an overview of filterable predefined fields. Note that not all of these have filtering enabled by default, see Allowed Filters for additional information. It is also important to note that the field names are case sensitive.
Field | Type | Default Filterable |
---|---|---|
CategoryNames | Term | ✔ |
CategoryIds | Term | ✔ |
Price | Range | ✔ |
SearchableIds | Term | ✔ |
InStock | Term | ✔ |
Inactive | Term | ✘ |