Index definitions
Index definitions helps Ucommerce figure out what data you want in your index as well as what data type it has and how you can search the index.
It is a generic concept which means you can define any index of data you could possible imagine.
OOTB Index Definitions
Ucommerce ships with a couple of index definitions out of the box. We realize that this isn't enough, and that you possibly have an opinion on how your data should look like.
Ucommerce ships with an index per catalog concept e.g.
- Stores
- Catalogs
- Categories
- Products
- Price Groups
A word on definitions and custom properties on catalog items
Each catalog item type has the ability to be extended with custom data via definitions. This data will not be part of the index unless you override the default index definitions.
Out of the box all Index Definitions will have the standard data fields indexes like name and multi lingual properties as well as images and other essential parts of the catalog data set.
All Default Index definitions can be found under the following namespace.
using Ucommerce.Search.Definitions; using Ucommerce.Search.Extensions;
Product Index Definition
To have custom data defined in the index you can create an implementation that inherits the default product index definitions.
public class AvenueProductIndexDefinition : Ucommerce.Search.Definitions.DefaultProductsIndexDefinition { public AvenueProductIndexDefinition() : base() { this.Field(p => p["ShowOnHomepage"], typeof(bool)) .DisplayName("da-DK", "Vis på forsiden") .DisplayName("en-US", "Show on home page"); this.Field(p => p["CollarSize"], typeof(string)); this.Field(p => p["ShoeSize"], typeof(string)); this.Field(p => p["Colour"], typeof(string)); this.Field(p => p.UnitPrices); this.Field(p => p.PricesInclTax); this.Facet("Colour"); this.Facet("CollarSize"); this.Facet("ShoeSize"); //price field and ranges this.Field(p => p.UnitPrices["USD 7 % VAT"]) .Facet() .AutoRanges(count: 5, precision: 100); } }
The code above defines the data needed to power Avenue-Clothing. Now Ucommerce will pick this definition up when the configuration has been created as well.
The following configuration register the avenue-clothing product index definition and now the right data needed is indexed properly.
<component id="ProductsIndexDefinition" service="Ucommerce.Search.IIndexDefinition`1[[Ucommerce.Search.Models.Product, Ucommerce.Search]], Ucommerce.Search" type="AvenueClothing.Search.AvenueProductIndexDefinition, AvenueClothing"> </component>
Facets
Facets are part of the index definition like everything else defined for your indexes. To learn more, read about facets and how to configure them
More Index Definitions
If you want to add custom data to the rest of the catalog concepts, the framework is exactly the same as for Product Index Definition. All you will have to modify is the namespace you inherit, the component id in the config, and the Ucommerce.Search.Model in the service of the config.
Here are the configs you will need with the different namespaces:
Ucommerce.Search.Definitions.DefaultProductCatalogGroupsIndexDefinition
<component id="ProductCatalogGroupsIndexDefinition" service="Ucommerce.Search.IIndexDefinition`1[[Ucommerce.Search.Models.ProductCatalogGroup, Ucommerce.Search]], Ucommerce.Search" type="Your.Custom.Namespace.CustomProductCatalogGroupsIndexDefinition, YourDll"> </component>
Ucommerce.Search.Definitions.DefaultProductCatalogsIndexDefinition
<component id="ProductCatalogsIndexDefinition" service="Ucommerce.Search.IIndexDefinition`1[[Ucommerce.Search.Models.ProductCatalog, Ucommerce.Search]], Ucommerce.Search" type="Your.Custom.Namespace.CustomProductCatalogsIndexDefinition, YourDll"> </component>
Ucommerce.Search.Definitions.DefaultCategoriesIndexDefinition
<component id="CategoryIndexDefinition" service="Ucommerce.Search.IIndexDefinition`1[[Ucommerce.Search.Models.Category, Ucommerce.Search]], Ucommerce.Search" type="Your.Custom.Namespace.CustomCategoryIndexDefinition, YourDll"> </component>
Ucommerce.Search.Definitions.DefaultPriceGroupsIndexDefinition
<component id="PriceGroupIndexDefinition" service="Ucommerce.Search.IIndexDefinition`1[[Ucommerce.Search.Models.PriceGroup, Ucommerce.Search]], Ucommerce.Search" type="Your.Custom.Namespace.CustomPriceGroupIndexDefinition, YourDll"> </component>