Ucommerce
  • Ucommerce Next Gen
    • Getting Started
      • Prerequisites
      • Licensing
      • Ucommerce Templates
      • Headless Template
      • MVC Template
    • Headless
      • Postman Collection
      • Headless API Authentication
        • Token endpoint - Authorization Header
        • Authorization Scopes
        • Refreshing the Access Token
      • Reference
        • Cart
        • Cart / Order Line Items
        • Shipment
        • Billing
        • Promotion Codes
        • Price Groups
        • Payment Methods
        • Countries
        • Shipping Methods
        • Catalogs
        • Cart Custom Properties
        • Line Item Custom Properties
        • Orders
        • Views for Cart modifying operations
      • Custom Headless APIs
      • Error Handling
      • Pagination
      • Deprecation
    • Backoffice Authentication
      • Microsoft Entra ID Example
      • Auth0 Authentication Example
    • Definitions
      • What is a Definition
    • Search and indexing
      • Configuration
      • Indexing
        • Index Definitions
        • Facets
        • Indexing Prices
        • Suggestions
        • Custom Data
      • Searching
    • Payment Providers
      • Stripe Provider Integration
      • Implementing a custom payment provider
    • Data Import
    • Miscellaneous
      • Media
      • Price Group Inheritance
      • Price Group Criteria
      • Soft Deletion Of Entities
      • Logging
      • OpenTelemetry
    • Extensions
      • Extending Pipelines
        • Order Processing Pipelines
        • Checkout Pipelines
      • Changing Service Behavior
        • Images
        • Content
      • Custom Headless APIs
      • Extend the Backoffice
        • Custom UI Components
      • Custom Editor UI
      • Custom Promotion Criteria
      • Custom Price Group Criteria
    • How-To
      • Migrate from Classic
        • Common database issues
      • Entities from code
        • Bootstrapping data on startup
        • Product Definitions & Fields
      • Discover pipelines and their tasks
      • Executing a pipeline
    • Integrations
      • Umbraco Media Delivery API
      • App Slices
        • Product Picker
  • Release Notes
  • Contact Us
Powered by GitBook
On this page
  • Default index definitions
  • Customizing an index definition
  • Enum fields
  • Multi-value fields
  • Translation of values

Was this helpful?

  1. Ucommerce Next Gen
  2. Search and indexing
  3. Indexing

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.

public class CustomProductIndexDefinition : DefaultProductsIndexDefinition
    {
        public CustomProductIndexDefinition()
        {
            this.Field(p => p["Color"], typeof(UserDefinedEnum));
            this.Field(p => p["Coupons"], typeof(UserDefinedEnum));
            this.Field(p => p["Downloadable"], typeof(bool));

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

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:

this.Field(p => p.VariantsProperties)

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

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

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.:

"Coupons": [
  {
    "DisplayName": "5 coupons",
    "Value": "5"
  },
  {
    "DisplayName": "10 coupons",
    "Value": "10"
  },
  {
    "DisplayName": "15 coupons",
    "Value": "15"
  }
],
"Downloadable": [
  "on"
]

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.

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.

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

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.

Splitting multi-value fields is not limited to UserDefinedEnum . Other types, like strings, can also be used.

To make sure that the system can automatically split the values, use Ucommerce.Web.Infrastructure.Constants.DATA_SPLITTING_CHARACTER to join the values.

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.

PreviousIndexingNextFacets

Last updated 5 months ago

Was this helpful?

See below for more details on how the multilingual display name is translated.

translation of values