---
title: Language routing
slug: cms-12/docs/language-routing-1
docTags: 
createdAt: 2026-08-10T15:55:54.000Z
---

The language routing feature for Search & Navigation limits search queries to documents in a specified language, making 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 implement `ILocale`, such as `PageData`, `ProductContent`, `NodeContent`, and `VariationContent`.

## Add language routing

The language routing feature limits search queries to documents in a specified language.

Language routing makes querying more precise by reducing the number of false positive matches because it analyzes documents for only one language. Because language routing optimizes indexing performance and increases query precision, you should use it when indexing documents. Language routing requires no change to search queries.

Previously, Optimizely Search & Navigation analyzed documents for supported languages. This practice sometimes caused *noise* when one language's stemming rules collided with another's.

You can add language routing to any type of object with the `LanguageRoutingAttribute` or the conventions API.

### LanguageRoutingAttribute

You can add language routing with the `LanguageRoutingAttribute` on the property. Set it to the desired language when initializing the object.

```csharp
public class WithLanguageRoutingAttribute {
  [Id]
  public string Id {
    get;
    set;
  }
  [LanguageRouting]
  public LanguageRouting LanguageRouting {
    get;
    set;
  }
}

var indexedObject = new WithLanguageRoutingAttribute() {
  Id = "123",
    LanguageRouting = new LanguageRouting(Language.Swedish)
};
```

### Conventions

Another option is to use the conventions API in Search & Navigation.

```csharp
client.Conventions.ForInstancesOf<WithLanguageRouting>().LanguageRoutingIs(x => x.LanguageRouting);
```

## Disable language routing

You can turn off the language routing support by using conventions or overriding `LanguageRoutingFactory` as described in the following sections.

### Disable language routing using conventions

The following 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 `LanguageRouting`feature's performance improvements.

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

The following example 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.

```csharp
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.

```csharp
[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.

```csharp
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:

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

**Related blog post:** [Search & Navigation 13: New language routing](https://world.optimizely.com/blogs/Jonas-Bergqvist/Dates/2018/4/find-13-new-language-routing/)
