+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Search in multi-language

Search in multi-language

4 posts, 0 answered
  1. Nimit
    Nimit avatar
    90 posts
    Registered:
    27 Mar 2009
    07 Oct 2009
    Link to this post
    Hi,
    My website is bilingual, i.e. English and French.
    In search option while creating index how can we differentiate between English and French search results.
    Please reply ASAP.

    Regards,
    Nimit Verma.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Oct 2009
    Link to this post
    Hi Nimit,

    The easiest way will be modifying Search Results control and show only the desired language - for instance when your current culture is "en" you will show only results from "en" pages.

    Below is a sample code:

    1. Create a code behind of SearchResults control.
    2. Add the logic shown below

    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;  
                    }  
                }  
            }  
        }  

    By doing so we are accessing the ResultItem and hide it if is not from the current culture - we hide it. I hope this helps.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Nimit
    Nimit avatar
    90 posts
    Registered:
    27 Mar 2009
    07 Oct 2009
    Link to this post

    Hi Ivan Dimitrov,
    Thank you for your reply,
    but can you please tell what should I include for accessing "ResultItem" type.

    Thank you ,
    Nimit Verma.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Oct 2009
    Link to this post
    Hi Nimit,

    You are accessing the ResultItem from EventArgs of the repeater control. Each link ( result) is a result item. ResultItem is class that represents information about a document in a result set.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered