Just a quick blog on using Sitecore content search within multilingual sites.
A very basic way of achieving a multilingual search, i’ve used in the past involves building a query to filter on the language from the Sitecore.Context.Language. This method is explained in a previous tweet from Jamie Little and a blog post, however a comment from Stephen Pope shed more detail on content search, where you can actually pass in a culture into the content search.
So how does this work in practice
Within the Lucene or Solr configuration (e.g. “Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config”) we can see that there is a collection of analyzers specified along with the culture name the analyzer is for.
Switching analyzer for the given language
When constructing the context.GetQueryable<SearchResultItem> there is an overloaded method that accepts a CultureExecutionContext. This allows you to pass in a culture to use for the search, context search then uses the config to locate the correct analyzer for the given culture info.
In the example below, I get the current cultureInfo from the context language and pass this into the GetQueryable method. This allows content search to automatically switch between analyzers based on the current site language.