World is now on Opti ID! Learn more

Jonas Bergqvist
Jan 14, 2014
  6471
(0 votes)

Indexing catalog content using EPiServer Find Content Indexing Job

When developing a commerce site, a good search product might be the key to success. Working search driven can make the site fast, easy to understand, and simple to use. For me, EPiServer Find is the obvious choice when working with EPiServer Commerce.

Find search provider

When using EPiServer Find in a commerce site, you might end up using the “Find seach provider” on the site, which isn’t that good. Instead you should work with the strongly typed “catalog content”, that are being indexed when adding or updating content in the new catalog UI. The problem with the typed catalog content, is that there’s no indexing job for it.

So, why should we use catalog content (the content types you create in code) instead of the content stored by the find search provider? The Find search provider index the data untyped in different dictionaries. The provider system can be used for free text search and maybe an simple facet, but is not useful for more complex operations. Indexing the content types you have created, makes it possible to make strongly typed search queries, facets, and listings. All the properties you create in code, and all the properties in the base classes can be used in the search queries. The code will also be pretty and easy to understand when working against typed data. You will also get help from the compiler to write correct code when working with typed data.

Indexing catalog content using the find indexing job

We can make the “EPiServer Find Content Indexing Job” index catalog content for us using the code below.

[ServiceConfiguration(typeof(IReindexInformation))]
public class DescendetLinksOfCatalogRoot : IReindexInformation
{
    private readonly IContentLoader _contentLoader;
    private readonly ReferenceConverter _referenceConverter;
    private readonly ILanguageBranchRepository _languageBranchRepository;
 
    public DescendetLinksOfCatalogRoot(ReferenceConverter referenceConverter,
        IContentLoader contentLoader,
        ILanguageBranchRepository languageBranchRepository)
    {
        _contentLoader = contentLoader;
        _referenceConverter = referenceConverter;
        _languageBranchRepository = languageBranchRepository;
    }
 
    /// <summary>
    /// Returns all descendents of the <see cref="Root"/>.
    /// </summary>
    public IEnumerable<ReindexTarget> ReindexTargets
    {
        get
        {
            var catalogs = _contentLoader.GetChildren<CatalogContent>(Root);
            foreach (var catalogContent in catalogs)
            {
                var reindexTarget = new ReindexTarget()
                {
                    ContentLinks = _contentLoader.GetDescendents(catalogContent.ContentLink)
                };
 
                var languages = catalogContent.ExistingLanguages.ToList();
                if (!languages.Select(x => x.Name).Contains(catalogContent.DefaultLanguage))
                {
                    languages.Add(CultureInfo.GetCultureInfo(catalogContent.DefaultLanguage));
                }
 
                reindexTarget.Languages = languages;
                yield return reindexTarget;
            }
        }
    }
 
    /// <summary>
    /// Gets the reference of the catalog root.
    /// </summary>
    public ContentReference Root
    {
        get { return _referenceConverter.GetRootLink(); }
    }
}
Jan 14, 2014

Comments

Please login to comment.
Latest blogs
Make Global Assets Site- and Language-Aware at Indexing Time

I had a support case the other day with a question around search on global assets on a multisite. This is the result of that investigation. This co...

dada | Jun 26, 2025

The remote server returned an error: (400) Bad Request – when configuring Azure Storage for an older Optimizely CMS site

How to fix a strange issue that occurred when I moved editor-uploaded files for some old Optimizely CMS 11 solutions to Azure Storage.

Tomas Hensrud Gulla | Jun 26, 2025 |

Enable Opal AI for your Optimizely products

Learn how to enable Opal AI, and meet your infinite workforce.

Tomas Hensrud Gulla | Jun 25, 2025 |

Deploying to Optimizely Frontend Hosting: A Practical Guide

Optimizely Frontend Hosting is a cloud-based solution for deploying headless frontend applications - currently supporting only Next.js projects. It...

Szymon Uryga | Jun 25, 2025

World on Opti ID

We're excited to announce that world.optimizely.com is now integrated with Opti ID! What does this mean for you? New Users:  You can now log in wit...

Patrick Lam | Jun 22, 2025

Avoid Scandinavian Letters in File Names in Optimizely CMS

Discover how Scandinavian letters in file names can break media in Optimizely CMS—and learn a simple code fix to automatically sanitize uploads for...

Henning Sjørbotten | Jun 19, 2025 |