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

Forums / Developing with Sitefinity / Localized Search Results

Localized Search Results

13 posts, 1 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    15 Jul 2009
    Link to this post
    Hi There,

    I have a bilingual site, english and french. I have implemented the standard SearchBox and SearchResults controls and they reference an "AllPages" index. My issue is that if I'm viewing the site in English and do a search, for say a company name (so name is same in english and french) my search results return twice as many pages as required because it returns the English page then followed by the French page. This of course is not at  all desireable. Is there any way to easily toggle the Search Results to acknowledge the current culture? 

    Sorry if this has been asked already, I dug for quite a while but found nothing.

    Thanks in advance!
    Phill
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    23 Jul 2009
    Link to this post
    Hello Phill Hodgkinson,

    This is possible by modifying SearchResults control. You should subscribe for rptResults.ItemCreated event of the Repeater control. Then get the current culture. If it "en" then hide "fr" results and vice versa.

    Below is the code behind that you should create.

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


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Answered
  3. HRC
    HRC avatar
    44 posts
    Registered:
    16 Mar 2009
    30 Apr 2010
    Link to this post
    This approach works if you're *not* using paging.  If you are, the maximum number of items you'll be able to remove from the results is whatever your PagesRange property is set to.

    Can you suggest an alternate approach that respects the paging, and the page count results?

    Thanks,

    Chris
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Apr 2010
    Link to this post
    Hello HRC,

    Here is what you have to do to keep the paging.

    •   Create a custom control that inherits from Telerik.Search.WebControls.SearchResult.
    •   Override CreateChildControls() without calling the base if the localization is enabled.
    •   Use PathUtil.GetIndexPhysicalPath and HttpContext.Current.Request.QueryString to get data for the parameters that are passed by SearchBox control.
    •   Call SearchManager.Search to create generic list of ResultItem.
    •   Get the current culture and use UrlHelper.UnresolveLanguageUrl to check the language for each result item.
    •    After that you have to populate another list of ResultItem objects and bind it to the ResultsList repeater that you could access from the container.
    •    You have to initialize the pager and set its PageCount, SelectedPage properties. You should also subscribe for SelectedPageChanged event of the pager, so that you will get proper paging when you switch between the pages.


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. HRC
    HRC avatar
    44 posts
    Registered:
    16 Mar 2009
    30 Apr 2010
    Link to this post
    Was hoping you could elaborate more on this through the use of a code sample?

    Any and all help would be greatly appreciated as it was expected that search results would be culture-aware.

    Chris.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    02 May 2010
    Link to this post
    Hi HRC,

    You could take a look at Extending SearchResult

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    05 Mar 2011
    Link to this post
    Greetings,

    Is there a simpler way than rewriting the whole control in order to simply show the correct total of records found?
    We have a 5-language site. Any search lists the records found for a specific language (correctly) but the ResultsStats literal ("Found {0} pages for "{1}") displays the total of results from ALL languages (wrong).

    Thanks in advance.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Mar 2011
    Link to this post
    Hi Chanan,

    The total count is set in CreateChildControls, so this is the correct way to remove it. Inside CreateChildControls we generate the pager and its length is also populated based on the items bound to the main repeater of SearchRessults control.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  9. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    07 Mar 2011
    Link to this post
    Thanks for responding.
    Was trying to avoid writing a custom control.
    Is search control culture-aware in Sitefinity 4.0?

  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Mar 2011
    Link to this post
    Hi Chanan,

    In Sitefinity 4.0 the situation is the same. I hope that we will be able to provide a solution for Q2 release.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  11. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    07 Mar 2011
    Link to this post
    Thanks.
    What we ended up doing (client wants it ready today) is:

    In SearchResult.ascx:
    <asp:Literal ID="ResultsStats" runat="server" Text="<%$ Resources:ResultsFound %>"></asp:Literal>

    In SearchResult.ascx.resx:
    ResultsFound
    Found {0} pages for "{1}" in all languages.<
    br />Here are the results in your language: 

  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Mar 2011
    Link to this post
    Hi Chanan,

    That will mask the labels only. The pager will be wrong, because it is bound to entire datasource.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  13. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    07 Mar 2011
    Link to this post
    Thanks for the lightening-fast response.
    Is there a way to disable paging (for the time being we're looking for a quick and dirty fix to this problem -- and it is a puzzling, unexpected Sitefinity problem).

    Thanks.
Register for webinar
13 posts, 1 answered