Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Jonas Bergqvist
Apr 3, 2018
  957
(0 votes)

Find 13: New language routing

In order to optimize indexing performance, and increase query precision, indexing documents should be done by specifying language routing. The use of language routing, when indexing, does not require any changes when querying. The only effect language routing has on querying is that it increases query precision. This is done by reducing the number of false positive matches, as documents only are analyzed for a specific language. Previously, all documents were analyzed for all available languages supported, sometimes causing noise when stemming rules for one language collided with stemming rules for another.

Adding language routing on any type of object

Adding language routing for any type of object can be done in different ways.

LanguageRoutingAttribute

One option is to use LanguageRoutingAttribute on the property, and set it to the desired language when initializing the object.

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

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

CMS integration

The Find CMS integration automatically adds language routing support for content implementing ILocale. Most content base type, like PageData, ProductContent, NodeContent, and VariationContent, all implements ILocale. The behavior can be changed by either using conventions, or by overriding LanguageRoutingFactory.

Conventions

The following example changes the behavior for all content implementing ILocale, to store the documents in the old way. It’s not recommended to do this, because it prevents the performance improvements.

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

This example changes the behavior only for MediaData. You might want to do this for some specific content types, if it’s necessary to analyze the content using all analyzers.

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

LanguageRoutingFactory

A LanguageRoutingFactory is, by default, used for all ILocale content, to create language routing for content that implements ILocale. It’s possible to change the default behavior by creating your own factory that inherits from LanguageRoutingFactory, and override any of the protected virtual methods. You also need to register your language routing 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 behaviour, to use all analyzers instead of the “standard” analyzer, for all content which uses a language we can’t map 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;
     }
}

Reindex the site after upgrade to Find 13

The changes in the language routing make it necessary to reindex the site after upgrading to Find 13. The site will work directly when you start the site, before the content has been reindexed. It will work because queries will still hit the content that hasn’t been indexed using the language routing.

The problem (if site isn’t reindexed) will occur when content is reindexed after being triggered from a content event. The content might be stored in a different way as before, which might make the old content continue to exist. You can end up having the same content stored twice, but in different versions.

Conclusion: After upgrading to Find 13, reindex the whole site as soon as possible.

Apr 03, 2018

Comments

Please login to comment.
Latest blogs
Optimizely Configured Commerce and Spire CMS - Figuring out Handlers

I recently entered the world of Optimizely Configured Commerce and Spire CMS. Intriguing, interesting and challenging at the same time, especially...

Ritu Madan | Mar 12, 2025

Another console app for calling the Optimizely CMS REST API

Introducing a Spectre.Console.Cli app for exploring an Optimizely SaaS CMS instance and to source code control definitions.

Johan Kronberg | Mar 11, 2025 |

Extending UrlResolver to Generate Lowercase Links in Optimizely CMS 12

When working with Optimizely CMS 12, URL consistency is crucial for SEO and usability. By default, Optimizely does not enforce lowercase URLs, whic...

Santiago Morla | Mar 7, 2025 |

Optimizing Experiences with Optimizely: Custom Audience Criteria for Mobile Visitors

In today’s mobile-first world, delivering personalized experiences to visitors using mobile devices is crucial for maximizing engagement and...

Nenad Nicevski | Mar 5, 2025 |

Unable to view Optimizely Forms submissions when some values are too long

I discovered a form where the form submissions could not be viewed in the Optimizely UI, only downloaded. Learn how to fix the issue.

Tomas Hensrud Gulla | Mar 4, 2025 |

CMS 12 DXP Migrations - Time Zones

When it comes to migrating a project from CMS 11 and .NET Framework on the DXP to CMS 12 and .NET Core one thing you need to be aware of is the...

Scott Reed | Mar 4, 2025