Sitecore ContentSearch Language Based Search

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.

Advertisements

One thought on “Sitecore ContentSearch Language Based Search

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s