---
title: Setting analyzers for Azure Search
related:
  - https://docs.kentico.com/13/configuring-xperience/setting-up-search-on-your-website/using-azure-cognitive-search/creating-azure-search-indexes.md
  - https://docs.kentico.com/13/configuring-xperience/setting-up-search-on-your-website/using-azure-cognitive-search/customizing-azure-search.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Azure Search uses [Language analyzers](https://docs.microsoft.com/en-us/rest/api/searchservice/language-support) to process text values. By default, searchable fields are analyzed with the [Apache Lucene Standard analyzer](http://lucene.apache.org/core/4_9_0/analyzers-common/index.html). 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](https://docs.kentico.com/13/configuring-xperience/setting-up-search-on-your-website/using-azure-cognitive-search/customizing-azure-search.md) the functionality that Xperience uses to build Azure Search indexes:

1. Open your Xperience solution in Visual Studio.

2. Create a [custom module class](https://docs.kentico.com/13/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md).

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](https://docs.microsoft.com/en-us/rest/api/searchservice/language-support) into one of its _Analyzer_ properties.

      > **Info:** **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](https://docs.microsoft.com/en-us/rest/api/searchservice/create-index) 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](https://docs.kentico.com/13/custom-development/adding-custom-assemblies.md) (_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:

   ```csharp

   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.
