Loading...
Area: Episerver Search & Navigation
Applies to versions: 13 and higher

Language routing support

Recommendations [hide]

The Episerver Search & Navigation (formerly Episerver Find) integration with Episerver CMS includes language routing support for content that implements ILocale. This topic describes how to modify the support.

How it works

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 Episerver 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.

Disabling 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);

Disabling 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 LanguageRouting factory 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 topic

Do you find this information helpful? Please log in to provide feedback.

Last updated: Apr 25, 2019

Recommendations [hide]