Index Definitions

Index definitions specify the data type, content, and searchability of indexed data in Ucommerce.

Default index definitions

Ucommerce ships with built-in index definitions for the following entities:

  • Store

  • Catalog

  • Category

  • Product

  • PriceGroup

Customizing an index definition

To have custom data, e.g., user-defined fields, in your index definition, you must create a class that either inherits from IIndexDefintion<SearchModelType> or the default definition as in the example below.

public class CustomProductIndexDefinition : DefaultProductsIndexDefinition
        public CustomProductIndexDefinition()
            this.Field(p => p["Color"], typeof(string));
            this.Field(p => p["CollarSize"], typeof(string));
            this.Field(p => p["Coupons"], typeof(string));

            this.Field(p => p.ShortDescription)
            this.Field(p => p.PricesInclTax["EUR 15 pct"]);

If you inherit from the default definition, you get all the standard fields in addition to your custom fields. It's possible to exclude standard fields, as shown in the example above. If you want full control, inherit from the interface and explicitly add the fields you need.

After defining a custom index, it must be registered in the service collection of your app.

builder.Services.AddUnique<IIndexDefinition<ProductSearchModel>, CustomProductIndexDefinition>();

You need to rebuild your indices after changing your index definition.

Last updated