Search by language branch in EPiServer

by: Ted Nyberg (Hallvarsson & Halvarsson)

This post is a complement to my previous post about searching pages with EPiServer. I have gotten a few questions about how to limit a page search to include pages from a specific language branch. Since this is truly a basic requirement when performing page searches, I'd like to share a simple way of accomplishing it:

1) Set up your criteria collection

See my previous post on searching with EPiServer for details regarding the PropertyCriteria object and the FindPagesWithCriteria method.

2) Add a language branch criteria

PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
criteria.Name = "PageLanguageID";
criteria.Type = PropertyDataType.String;
criteria.Value = "sv"; //Find swedish page versions
criteria.Required = true; //Criteria must be met

//Add the criteria to your PropertyCriteriaCollection
//object, here named 'criterias'
criterias.Add(criteria);

 

There you go, that's all you need to add a language branch condition for your page search!

Don't forget the search post for details on how to implement the page search using FindPagesWithCriteria.

Update: As Per points out, you may use one of the FindPagesWithCriteria overloads to specify the language branch directly in the method call.

02 March 2008


Comments

  1. FindPagesWithCriteria actually has a overload that takes language id, I recommend that you use that one instead.
  2. I'm not familiar with the inner workings of the FindPagesWithCriteria method, but shouldn't the two approaches yield the same result? Although it requires less code to use the overload it does involve an inconsistent way of specifying criteria. Furthermore, if the criteria is being gathered dynamically across class boundaries it is nice to be able to simply pass a PropertyCriteriaCollection object.
  3. Why not just specify languagebranches for the SearchDataSource control?
Post a comment    
User verification Image for user verification  
Ted Nyberg (Hallvarsson & Halvarsson)

About me

I'm a consultant with the corporate communications consultancy Hallvarsson & Halvarsson, part of the transatlantic stakeholder management and financial communications firm Sage Holdings.

My focus areas include web applications, intranets, and corporate websites.

Live Messenger

Hallvarsson & Halvarsson logo
 MCPD, MCTS and MCP logos

Bloggtoppen.se


Syndications


Archive


Tag cloud

EPiTrace logger