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 (
DefaultStoresIndexDefinition
)Catalog (
DefaultCatalogsIndexDefinition
)Category (
DefaultCategoriesIndexDefinition
)Product (
DefaultProductsIndexDefinition
)PriceGroup (
DefaultPriceGroupsIndexDefinition
)ProductPrice (
DefaultPricesIndexDefinition
)
Customizing an index definition
To have custom data, e.g., user-defined fields, in the index, you must create a custom index definition by creating a class that either inherits from IIndexDefintion<SearchModelType>
or the default definition as in the example below.
If you inherit from the default definition, you get all the standard fields in addition to the fields added in the custom index definition class. 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.
By default, the property VariantProperties
is not populated when the search model is retrieved from the index. To access variant properties on the parent entity add the following to your custom index definition class:
After defining a custom index, it must override the default in the service collection of your app.
A rebuild of the indices is needed after changing the index definition.
Enum fields
When adding a user-defined enum, e.g. Color
, use the type UserDefinedEnum
in the index definition as shown in the example above. This type has special handling in the index to make sure that the display name and value of the enum is handled correctly, e.g.:
Notice that the Coupons
property has DisplayName
and Value
properties while Downloadable
does not. This is because Coupons
is defined as UserDefinedEnum
while Downloadable
is defined as bool
.
See translation of values below for more details on how the multilingual display name is translated.
Multi-value fields
When adding a multi-value field, e.g. available colors
, the API can automatically split this correctly into a list of possible values as shown below.
Example: Red and Green are the available colors for a product, then said product can be found by filtering on either Red or Green or both.
Translation of values
Since every index corresponds to a specific language, the system will automatically handle translation of multilingual user-defined fields. Therefore, if you have configured a user-defined field to be multilingual, the appropriate translation will be automatically available in each index. This makes the system highly flexible without requiring additional index configuration.
Last updated