+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

Separating search results in multilingual websites

by Ivan Dimitrov
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;  
                }  
            }  
        }  
    }  

4 comments

Leave a comment
  1. vardars Jun 02, 2010
    Used namespaces are:

    using System;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Globalization;

    using Telerik.Cms.Web;
    using Telerik.Search.Engine;
  2. Roman Jan 24, 2011
    Problem is that datasource still contains all items and displays wrong number of results and pagination doesn't work as well.
  3. khizar Jun 17, 2011
    Hi, I wana ask a question that Im trying to use your code in my .ascx file but i dont know how to add refernces in that file. I have added but they dont work. Could you please tell me the exact syntax for refernces for URLHelper and Culture.

    Thanks
  4. khizar Jun 17, 2011
    Hi, I wana ask a question that Im trying to use your code in my .ascx file but i dont know how to add refernces in that file. I have added but they dont work. Could you please tell me the exact syntax for refernces for URLHelper and Culture.

    Thanks

    Leave a comment