Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Reindexing

Reindexing is very important when modifying products. Out of the box Ucommerce re-indexes items when you modify them in the back-office. But sometimes your data might get out of sync, so you will need to reindex parts, or the entire Ucommerce structure. If the index is incomplete or if you're not sure about the status of it, you can do a reindex.

Reindexing can be done in two ways, one by indexing a single thing at a time, and one by scratchindexing, short for indexing everything from scratch.

Running the Scratch Indexer

The scratch indexer is a background process that runs all the indexers.
Triggering this will rebuild all the indexes from scratch.

When to run it

You should run the Scratch Indexer in cases where something has gone wrong with index, or if you need to be sure that the index is up to date with everything in it.
Running the Scratch Indexer can be a heavy operation, depending on how much data you have in the index.
So you should take that into account, and run it when needed.

How to run via UI

You can run the Scratch Indexer from the UI.
To do so, navigate to the "Search" node under "Settings" in Ucommerce, and press the "Index everything form scratch" button. View of back office with indexer button

How to run via code

You can also run the Scratch Indexer from your code like this:

    Ucommerce.Search.Indexers.IScratchIndexer scratchIndexer = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<IScratchIndexer>();
    scratchIndexer.Index();
    

Indexing single or multiple elements dynamically

To index a single item at a time, you can do it like this:

    
    Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.ProductCatalogGroup> catalogGroupIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.ProductCatalogGroup>>();
    Ucommerce.EntitiesV2.ProductCatalogGroup productCatalogGroup = Ucommerce.EntitiesV2.ProductCatalogGroup.All().First();
    catalogGroupIndexer.Index(productCatalogGroup);
    
    Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.ProductCatalog> catalogIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.ProductCatalog>>();
    Ucommerce.EntitiesV2.ProductCatalog productCatalog = Ucommerce.EntitiesV2.ProductCatalog.All().First();
    catalogIndexer.Index(productCatalog);
    
    Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.Category> categoryIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.Category>>();
    Ucommerce.EntitiesV2.Category category = Ucommerce.EntitiesV2.Category.All().First();
    categoryIndexer.Index(category);
    
    Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.PriceGroup> priceGroupIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.PriceGroup>>();
    Ucommerce.EntitiesV2.PriceGroup priceGroup = Ucommerce.EntitiesV2.PriceGroup.All().First();
    priceGroupIndexer.Index(priceGroup);
    
    Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.Product> productIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<Ucommerce.EntitiesV2.Product>>();
    Ucommerce.EntitiesV2.Product product = Ucommerce.EntitiesV2.Product.All().First();
    productIndexer.Index(product);
    
    

To index multiple items at once, you can do it like this:

    
    Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.ProductCatalogGroup>> catalogGroupListIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.ProductCatalogGroup>>>();
    System.Linq.IQueryable<Ucommerce.EntitiesV2.ProductCatalogGroup> productCatalogGroups = Ucommerce.EntitiesV2.ProductCatalogGroup.All().Where(x => x.Deleted == false);
    catalogGroupListIndexer.Index(productCatalogGroups);
    
    Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.ProductCatalog>> catalogListIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.ProductCatalog>>>();
    System.Linq.IQueryable<Ucommerce.EntitiesV2.ProductCatalog> productCatalogs = Ucommerce.EntitiesV2.ProductCatalog.All().Where(x => x.DisplayOnWebSite == true);
    catalogListIndexer.Index(productCatalogs);
    
    Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.Category>> categoryListIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.Category>>>();
    System.Linq.IQueryable<Ucommerce.EntitiesV2.Category> categories = Ucommerce.EntitiesV2.Category.All().Where(x => x.DisplayOnSite == true);
    categoryListIndexer.Index(categories);
    
    Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.PriceGroup>> priceGroupListIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.PriceGroup>>>();
    System.Linq.IQueryable<Ucommerce.EntitiesV2.PriceGroup> priceGroups = Ucommerce.EntitiesV2.PriceGroup.All().Where(x => x.Deleted == false);
    priceGroupListIndexer.Index(priceGroups);
    
    Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.Product>> productListIndexer = ObjectFactory.Instance.Resolve<Ucommerce.Search.IIndexer<System.Collections.Generic.IEnumerable<Ucommerce.EntitiesV2.Product>>>();
    System.Linq.IQueryable<Ucommerce.EntitiesV2.Product> products = Ucommerce.EntitiesV2.Product.All().Where(x => x.DisplayOnSite == true);
    productListIndexer.Index(products);