AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)
  1. Home
  2. Configuring Xperience
  3. Setting up search on your website
  4. Using Azure Cognitive Search
  5. Customizing Azure Search
  6. Setting analyzers for Azure Search

Setting analyzers for Azure Search


Was this page helpful?

Send us feedback Go back to top

Azure Search uses Language analyzers⁠ (opens in a new tab) to process text values. By default, searchable fields are analyzed with the Apache Lucene Standard analyzer⁠ (opens in a new tab). Because Azure Search supports a variety of languages, it additionally provides other text analyzers with more advanced capabilities for specific languages.

If you wish to assign a specific analyzer to the fields of an index, customize the functionality that Xperience uses to build Azure Search indexes:

  1. Open your Xperience solution in Visual Studio.

  2. Create a custom module class.

  3. Override the module's OnInit method and assign a handler to the DocumentFieldCreator.Instance.CreatingField.After event.

  4. Perform the following in the event's handler method:

    1. Write a condition to limit which search indexes and fields are affected by the analyzer customization (using values of the SearchIndex and SearchField properties of the handler's CreateFieldEventArgs parameter).

    2. Access the Field property of the handler's CreateFieldEventArgs parameter, and assign a valid analyzer name⁠ (opens in a new tab) into one of its Analyzer properties.

      Field analyzer properties

      The Field class (Microsoft.Azure.Search.Models.Field) offers the following properties for setting the analyzer:

      • Analyzer
      • IndexAnalyzer (used at indexing time)
      • SearchAnalyzer (used at search time)

      For more information, see the Index Attributes section of the Create Index⁠ (opens in a new tab) article.

  5. Also deploy the custom module class to the MVC application (otherwise indexing may not work correctly for changes performed through the live site).

  6. Open the administration interface.

  7. Open the Smart search application and Rebuild any related Azure Search indexes.

The customized Azure Search index fields now use the specified language analyzer.

Example

The following example demonstrates how to set the language analyzer for the skudescription field of an Azure Search index named dg-store.

Start by preparing a separate project in your Xperience solution for the custom module class:

  1. Open your Xperience solution in Visual Studio.
  2. Add a custom assembly (Class Library project) with class discovery enabled to the solution, or re-use an existing assembly.
  3. Reference the project from both your live site and Xperience administration (CMSApp) projects.

Continue by implementing the custom module class and rebuilding the related search index:

  1. Create a new class named CustomAzureSearchModule under the SearchCustomization project, with the following code:

    C#
    using System;
    
    using CMS;
    using CMS.DataEngine;
    using CMS.Search.Azure;
    
    // Registers the custom module into the system
    [assembly: RegisterModule(typeof(CustomAzureSearchModule))]
    
    public class CustomAzureSearchModule : Module
    {
        // Module class constructor, the system registers the module under the name "CustomAzureSearch"
        public CustomAzureSearchModule()
            : base("CustomAzureSearch")
        {
        }
    
        // Contains initialization code that is executed when the application starts
        protected override void OnInit()
        {
            base.OnInit();
    
            // Assigns a handler to the CreatingField.After event for Azure Search indexes
            DocumentFieldCreator.Instance.CreatingField.After += UseCustomSearchAnalyzer;
        }
    
        private void UseCustomSearchAnalyzer(object sender, CreateFieldEventArgs e)
        {
            string indexName = e.SearchIndex.IndexCodeName;
            string fieldName = e.SearchField.FieldName;
    
            // Sets the 'en.microsoft' analyzer for the 'skudescription' field in the 'dg-store' index
            if (indexName.Equals("dg-store", StringComparison.InvariantCultureIgnoreCase)
                && fieldName.Equals("skudescription", StringComparison.InvariantCultureIgnoreCase))
            {
                e.Field.Analyzer = "en.microsoft";
            }
        }
    }
  2. Save all changes and Build the SearchCustomization project.

  3. Sign in to the Xperience administration interface.

  4. Open the Smart search application and Rebuild the dg-store index.

The skudescription field of the dg-store index now uses the "en.microsoft" language analyzer, both during indexing and at search time.

Related pages

  • Creating Azure Search indexes
  • Customizing Azure Search