Sitecore Searching returns all languages from the Index

A quick one for today, something to be mindful of when performing a Sitecore Search against the indexes – what will be returned from your search will be a SearchResultItem for all languages that you have stored in your index, not just the language context.

You will need to perform the language filtering yourself 🙂
Quickest way of doing this is to either filter after the search has been done:


if (searchHit.Document.Language == Sitecore.Context.Language.Name)
{

  // your other code

}

.. or make it part of the search query


SearchResults<SearchResultItem> searchResults = context.GetQueryable<SearchResultItem>()
  .Filter(x => x.TemplateId == filterTemplace)
  .Filter(y => y.Language == Sitecore.Context.Language.Name)
  .GetResults();

Simple eh?

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s