HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In

Language routing support

Describes how to modify language routing support for content that implements ILocale, which is part of the Optimizely Search & Navigation integration with Optimizely Content Management System (CMS).

The Language routing feature for Search & Navigation limits search queries to documents in a specified language. The feature makes querying more precise by reducing the number of false positive matches, since documents are only analyzed for one language.

Most Optimizely Content Management System (CMS) content base types, like PageData, ProductContent, NodeContent, and VariationContent, implement ILocale. You can disable the language routing support by using conventions or overriding LanguageRoutingFactory as described in the following.

Disable using conventions

This example disables the LanguageRouting support through conventions. Here we change the behavior of content that implements ILocale by storing documents in the "old" way. This is not recommended since it negates the LanguageRouting feature's performance improvements.

client.Conventions.ForInstancesOf<ILocale>().LanguageRoutingIs(x => null);

The example below changes the behavior for MediaData only. You might want to do this for specific content types for example if you need to analyze content using all analyzers.

client.Conventions.ForInstancesOf<MediaData>().LanguageRoutingIs(x => null);

Disable via LanguageRoutingFactory

By default, LanguageRoutingFactory adds language routing to content that implements ILocale. To disable the default behavior, create your own factory that inherits from LanguageRoutingFactory, and override any protected virtual methods. You also need to register your custom LanguageRoutingfactory using a configurable module.

[InitializableModule]
[ModuleDependency(typeof(IndexingModule))]
public class MyFindInitializationModule : IConfigurableModule
  {
     public void Initialize(InitializationEngine context)
       {
       }
     public void Uninitialize(InitializationEngine context)
       {
       }
     public void ConfigureContainer(ServiceConfigurationContext context)
       {
         context.Services.AddSingleton<LanguageRoutingFactory, MyLanguageRoutingFactory>();
       }
  }

The following example changes the behavior to use all analyzers instead of the “standard” analyzer for all content whose language cannot be mapped to any analyzer.

public class MyLanguageRoutingFactory : LanguageRoutingFactory
  {
     public override LanguageRouting CreateLanguageRouting(ILocale locale)
       {
         var languageRouting = base.CreateLanguageRouting(locale);
         if (languageRouting.FieldSuffix == Language.None.FieldSuffix)
           {
             return null;
           }
         return languageRouting;
       }
  }

To disable language routing completely use the following override:

public class MyLanguageRoutingFactory : LanguageRoutingFactory
  {
    public override LanguageRouting CreateLanguageRouting(ILocale locale)
      {
        return null;
      }
  }

Related blog post: Search & Navigation 13: New language routing