Facets

Faceted search is the ability to narrow a search based on one or more dimensions.

Overview

When using Ucommerce, you can create a custom index definition that specifies which fixed or user-defined properties on your products should be generated as facets. Once you have completed this step, any queries against the index will return facets and their respective values, as shown in the image below.

Creating a facet

When you want to enable faceted search for a field, your index definition needs to define the field to be part of the index.

this.Field(p => p["Colour"], typeof(string))
    .Facet();

The search API will automatically retrieve all possible values for facets.

Multi-value fields

If you have defined a multi-select enum, for example, available colors, you can have the API automatically split this correctly into multiple possible values. If you have, fx. Red and Green for your available colors, you'll be able to find said entity by filtering on either Red or Green or both. This is shown in the example below.

this.Field(p => p["availableColors"], typeof(IEnumerable<string>))
    .Facet();

Price facets

Prices are special compared to most other fields and must be configured individually for each price group.

this.Field(p => p.UnitPrices["EUR 15 % VAT"])
    .Facet()
    .AutoRanges(count: 5, precision: 10);
 
this.Field(p => p.UnitPrices["USD 7 % VAT"])
    .Facet()
    .AutoRanges(count: 5, precision: 100);

Translation of values

The facets will adjust accordingly since every index corresponds to a specific language. Therefore, if you have configured a custom field to be multilingual, the appropriate translation will be automatically available. This feature makes the system highly flexible without requiring additional index configuration.

Last updated