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

Forums / Developing with Sitefinity / Multi-language site with search result

Multi-language site with search result

9 posts, 0 answered
  1. Developer
    Developer avatar
    1 posts
    Registered:
    18 Apr 2008
    12 Nov 2008
    Link to this post
    Hi there,

    I am having a problem with multilanguage search result.
    I have a  multilanguage site ( English, Dutch and Danish).
    When I am in the English site, and search for something using Search Box, Only English content should be displayed. But this did not happen because I saw content from all languages.  Is there a ways to configure so that the search only displays a spefic language whare a user've selected.

    Another wierd sutff is that I am in the English site, I saw a link that link to http://localhost/default.aspx but when i click on it, it send me to the default language (in this case, dutch site).

    I look forward to hearing from you.

    Regards,

    Sirilak Pompan
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    20 Nov 2008
    Link to this post
    Hi Developer,

    We regret to inform you that indexing by language is still not supported. This means that the search engine is looking for the term in all indexed content, which is not separated by language.

    We will discuss this feature for inclusion in the product though.

    All the best,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    25 Jun 2009
    Link to this post
    Greetings,

    Any news regarding the multilingual search?
    If language-specific search is not yet available, what would be the best way to go about it? Creating our own custom indexClient, etc.?

    Thanks in advance.
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    25 Jun 2009
    Link to this post
    Hi Chanan Zass,

    The multilingual search is not available yet.
    Creating a new search index will do the trick though. You should supply the different URLs with the language information the indexer. A webinar on this will be posted in several days on sitefinitywatch.com. I am sure that you will find it helpful.

    Georgi
    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.
  5. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    25 Jun 2009
    Link to this post
    Thanks.
    I've actually taken part in this webinar today.
  6. Jan
    Jan avatar
    39 posts
    Registered:
    22 Jan 2010
    13 Apr 2011
    Link to this post
    Is there any support for this now?

    I know that I have the option to create searchindex for each language, but all language share the same template and I have the searchbox in the template. I can change so the searchbox lay on the page, but that requires more from the editor when they set up a page. The need to set the searchbox AND point it to a specific index.
    That's not so user friendly and is a source for errors

    Maybe I could create a new search controls that sets the index based on CurrentUICulture? Takes away the option for the user but I will be able to include this in the template instead of the Page.
    Another way around it would be to create language specific templates by duplicate the current one.

    Is this how I have to handle it or is there a "better way" ?
  7. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    13 Apr 2011
    Link to this post
    You might want to take a look here:
    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/localized-search-results.aspx

    Also, the following code was sent to us by Ivan Dimitrov. You may use it to create a custom search control. You should still change it to define page total and page number.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Search.WebControls;
    using System.Web.UI;
    using System.IO;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Web.UI;
    using Telerik.Search.Common;
    using Telerik.Search.Engine;
    using Telerik.Utilities;
    using System.Globalization;
    using Telerik.Cms.Web;
    using System.ComponentModel;
    using Telerik.Framework.Web;
    using Telerik.Localization;
        
    /// <summary>
    /// Summary description for SearchResultsCustom
    /// </summary>
    ///
        
    public class ResultToolboxItemCustom : System.Drawing.Design.ToolboxItem
    {
        public ResultToolboxItemCustom()
            : base(typeof(SearchResultsCustom))
        {
            base.DisplayName = "CustomSearch";
            base.Description = "Custom Search Control";
        }
    }
        
    [System.ComponentModel.ToolboxItem(typeof(ResultToolboxItemCustom))]
    public class SearchResultsCustom : SearchResult
    {
        public SearchResultsCustom()
        {
        }
        
        
        
        /// <summary>
        /// Gets or sets the template used by SearchResult control
        /// </summary>
        [Browsable(false)]
        [DefaultValue((string)null)]
        [TemplateContainer(typeof(SearchResult), BindingDirection.OneWay)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate LayoutTemplate
        {
            get
            {
                if (this.layoutControlTemplate == null)
                    this.layoutControlTemplate = ControlUtils.GetTemplate<DefaultTemplate>(this.CustomControlLayoutTemplatePath);
                return this.layoutControlTemplate;
            }
            set
            {
                this.layoutControlTemplate = value;
            }
        }
        
        
        protected override void CreateChildControls()
            {
                base.CreateChildControls();
        
        
                this.layoutCnt.ResultsList.ItemDataBound += new RepeaterItemEventHandler(ResultsList_ItemDataBound);
                this.layoutCnt.ResultsList.DataBind();
        
                this.Controls.Clear();
        
                this.layoutCnt = new Container(this);
                this.LayoutTemplate.InstantiateIn(layoutCnt);
        
                if (!string.IsNullOrEmpty(Query))
                {
                    string vPath = PathUtil.GetIndexPhysicalPath(this.IndexCatalogue);
                    if (Directory.Exists(vPath))
                    {
                         
                        if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[PageKey]))
                        {
                            this.CurrentPage = Convert.ToInt32(
                                HttpContext.Current.Request.QueryString[PageKey]);
                        }
        
                        string searchQuery = Query;
                        string message = string.Empty;
        
                        bool isValid = this.EscapeSpecialChars ? this.EscapeSpecialChars : ValidateQuery(ref searchQuery, out message);
        
                        if (isValid)
                        {
                            int totalItems;
                            int startIndex = (this.CurrentPage - 1) * this.PostsPerPage;
        
                            try
                            {
                                IList<ResultItem> dataSource = SearchManager.Search(
                                    searchQuery,
                                    this.IndexCatalogue,
                                    startIndex,
                                    this.PostsPerPage,
                                    this.WordsMode,
                                    this.EscapeSpecialChars,
                                    out totalItems);
        
                                IList<ResultItem> newList = new List<ResultItem>();
                                foreach (ResultItem item in dataSource)
                                {
                                    CultureInfo itemCulture = null;
                                    var url = UrlHelper.UnresolveLanguageUrl(item.Url, out itemCulture);
                                    if (itemCulture != null && itemCulture == CultureInfo.CurrentUICulture)
                                    {
                                        newList.Add(item);
                                    }
                                    if (itemCulture ==null && CultureInfo.CurrentUICulture  == LocalizationManager.DefaultCulture)
                                    {
                                        // we assume that English is set as default culture in this case itemCulture is null
                                        newList.Add(item);
                                    }
                                }
                                    
                                var newPagingHacked = 10;
                                int numberOfPages = (this.PostsPerPage == 0) ? 1 : (int)Math.Ceiling((double)newList.Count / (double)newPagingHacked);
        
                                if (numberOfPages == 0 && newList.Count > 0)
                                    numberOfPages = 1;
        
                                string qeryTest = this.Query.Trim('\"');
                                ((Control)this.layoutCnt.ResultsStats).EnableViewState = false;
                                this.layoutCnt.ResultsStats.Text = string.Format(this.layoutCnt.ResultsStats.Text, newList.Count, qeryTest);
        
                                if (this.AllowPaging)
                                {
                                    this.layoutCnt.Pager1.SelectedPageChanged += new EventHandler<EventArgs>(Pager_SelectedPageChanged);
                                    this.layoutCnt.Pager1.PageCount = numberOfPages;
                                    this.layoutCnt.Pager1.SelectedPage = this.CurrentPage;
                                }
                                this.layoutCnt.ResultsList.DataSource = newList;
        
                            }
                            catch (Telerik.Lucene.Net.QueryParsers.ParseException ex)
                            {
                                this.layoutCnt.ResultsStats.Text = "there are strange chars";
                                Log.Exception(ex);
                            }
                        }
                        else
                        {
                            this.layoutCnt.ResultsStats.Text = message;
                        }
                    }
                    else
                    {
                        this.layoutCnt.ResultsStats.Text = String.Format("InvalidIndex", this.IndexCatalogue);
                    }
                }
                else
                {
                    this.layoutCnt.ResultsStats.Text = String.Empty;
                }
        
                this.layoutCnt.ResultsList.ItemDataBound += new RepeaterItemEventHandler(ResultsList_ItemDataBound);
                this.layoutCnt.ResultsList.SkinID = this.SkinID;
        
                Controls.Add(this.layoutCnt);
                this.layoutCnt.ResultsList.DataBind();
        
            }
        
        
        void ResultsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Footer)
            {
                if (!this.AllowPaging)
                {
                    e.Item.Controls.Clear();
                    return;
                }
            }
        }
        
        void Pager_SelectedPageChanged(object sender, EventArgs e)
        {
            this.CurrentPage = ((Pager)sender).SelectedPage;
            this.ChildControlsCreated = false;
        }
        
        protected ITemplate layoutControlTemplate;
        private string CustomControlLayoutTemplatePath = "~/CustomControls/SearchResults.ascx";
    }
  8. Jan
    Jan avatar
    39 posts
    Registered:
    22 Jan 2010
    14 Apr 2011
    Link to this post
    Hi

    Thanks for fast reply
    That code almost works but I can't get the Template to load

    I'm getting a

    A required control was not found in the template for "". The control must be assignable form type "System.Web.UI.Control" and must have ID "ResultsStats".

    If I look at the template file the ResultsStats exists. What I find strange is that the error is complaining about template "" (empty). I'm thinking that the template is not loaded att all.

    I have changed the CustomControlLayoutTemplatePath path to \Sitefinity\ControlTemplates\Search\SearchResult.ascx . What I figured it is not this propery that is displayed in admin?

    I have tried to search for other post about this and tried a couple of tips, but not getting it to work.

    Any ideas?



    EDIT: It was a typo in path!! Problem solved...
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Apr 2011
    Link to this post
    Hello Jan,

    You need to add a control  with ID ResultsStats in your template. This should be a Literal or Label, a control that implements ITextControl interface.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

Register for webinar
9 posts, 0 answered