Separating search results in multilingual websites

November 05, 2009 Digital Experience
If you have a bilingual or multilingual Sitefinity based website that uses standard SearchBox and SearchResults controls with reference to all pages you will see that the SearchResults control will return all ResulItems no matter of the culture you use. So it will be not useful for my English speaking visitors to see dutch result items in the list. You can easily get the current culture and "filter" the ResultItems that will be shown.

 

1. Locate the template of ResultItems control - SearchResult.ascx under ~/Sitefinity/ControlTemplates/Search.

2. I have to create a code behind of this template and subscribe for the ItemDataBound event of the repeater that lists all items. Then I am getting the current culture and hiding all items( cms pages) with culture different than the current.

protected void Page_Load(object sender, EventArgs e)  
    {  
        this.rptResults.ItemCreated += new RepeaterItemEventHandler(rptResults_ItemCreated);  
    }  
  
    void rptResults_ItemCreated(object sender, RepeaterItemEventArgs e)  
    {  
        if (e.Item.ItemType == ListItemType.Item   
            || e.Item.ItemType == ListItemType.AlternatingItem)  
        {  
            var item = e.Item.DataItem as ResultItem;  
            if (item != null)  
            {  
                CultureInfo itemCulture = null;  
                string url = UrlHelper.UnresolveLanguageUrl(item.Url, out itemCulture);  
                if (itemCulture != null && itemCulture != CultureInfo.CurrentUICulture)  
                {  
                    e.Item.Visible = false;  
                }  
            }  
        }  
    }  

The Progress Team