HomeDev guideAPI ReferenceGraphQL
Dev guideUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Language routing

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 because documents are only analyzed for one language.

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

Disable language routing using conventions

This example disables the LanguageRouting support through conventions by changing the behavior of content that implements ILocale by storing documents in the "old" way, which you should not do because it negates the LanguageRoutingfeature'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 language routing by way of LanguageRoutingFactory

By default, LanguageRoutingFactory adds language routing to content that implements ILocale. To turn off the default behavior, create your 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 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 turn off 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