Try Now
More in this section

Forums / Developing with Sitefinity / Custom search index in combination with custom sitemap

Custom search index in combination with custom sitemap

2 posts, 0 answered
  1. Jan
    Jan avatar
    39 posts
    22 Jan 2010
    01 Feb 2011
    Link to this post
    We created a custom sitemap to handle a menu structure for our product database.
    Now I have created a search index provider that gets the data to be indexed

    public IIndexerInfo[] GetContentToIndex()
         List<IIndexerInfo> list = new List<IIndexerInfo>();
      SiteMapNode node = SiteMap.Providers["SharePointSiteMap"].RootNode;
       if(node is SharePointWeb.Providers.SharepointSitemapNode)
         SharepointSitemapNode spNode = (SharePointWeb.Providers.SharepointSitemapNode)node;
           list.Add(new SharepointSearchInfo(spNode));
        // handle childs and so on
         return list.ToArray();

    As you can se we are sending the SharepointSitemapNode into the IIndexerInfo class and we then uses this in the GetData() function
    The GetData() uses a HttpWebRequest to fetch the page, strips the html tags and returns the raw text. This all works fine... BUT!SharepointSitemapNode

    The SharepointSitemapNode is a bit tricky. The node reads some properties if it is accessible for diffrent languages. This by using a Published flag. So when we print our menu we check

    if (!((SharepointSitemapNode)node).Published)

    the published flag make use of the CurrentLocale and check if the Node should be accessable.

    What I want to do is to use handle the Published flag in my index. Since the GetData function in IIndexerInfo returns the data in bytes[] i'm guessing I couldn't access anything from the searchresult control template.

    What I think I should do is to create a search index for each local and have each search page have it's localized search index. But when I try to call the Published flag from GetData it always returns null. Is the searchindex running with no Culture activated or why can't I get the Published flag to work?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    05 Feb 2011
    Link to this post
    Hello Jan Arenö,

    Thank you for using our services.

    Since our pages use localization the idexer must get all of the page's languages and fill it in the content to index. Bellow is some methods which are called when the indexer executes GetContentToIndex method. When we get a child page we check if localization is enabled, and if yes then get all language versions:
    foreach (IPageContent pageContent in page.LanguageVersions.Values)
        cult = CultureInfo.GetCultureInfo(pageContent.LangID);
        url = page.DefaultUrl.Url;
        cult = LocalizationHelper.GetPageCulture(pageContent);
        list.Add(GetPageIndexerInfo(url, page.ID, cult));

    The GetPageIndexerInfo method creates a new instance of PageIndexerInfo and passes the culture to the properties.

    Then when GetData() method for each PageIndexerInfo item in the collection of items we check if the culture field is set. If this culture field is set we set the current UI culture of the thread to this culture:
    CultureInfo cultureBackup = new CultureInfo();
        cultureBackup = System.Threading.Thread.CurrentThread.CurrentUICulture;
        System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(this.culture);

    This is all done in the method GetInternalPageData which gets the actual html to be indexed for the page:
    /// Returns internal page contents for indexing
    /// </summary>
    /// <returns>byte[]</returns>
    protected virtual byte[] GetInternalPageData()
        HttpContext context = HttpContext.Current;
        CultureInfo cultureBackup = null;
        context.Items["SF_Crawler"] = true;
        HttpServerUtility server = context.Server;
        if (!String.IsNullOrEmpty(this.culture))
            cultureBackup = System.Threading.Thread.CurrentThread.CurrentUICulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(this.culture);
        //CmsUrlContext.Current = UrlHelper.GetUrl(this.pageId);
        using (StringWriter writer = new StringWriter())
                IndexInternalPageHandler pageHandler = new IndexInternalPageHandler(writer, this.url, this.pageId, this.culture);
                pageHandler.AppRelativeVirtualPath = context.Request.AppRelativeCurrentExecutionFilePath;
                server.Execute(pageHandler, writer, false);
            catch (Exception ex)
                if (Log.CheckSecurityPermission())
                    Log.Exception(new IndexExcepton(String.Format(Messages.IndexingError, this.url), ex));
                return new byte[0];
                if (cultureBackup != null)
                    System.Threading.Thread.CurrentThread.CurrentUICulture = cultureBackup;
                context.Items["SF_Crawler"] = false;
            string htmlContent = writer.ToString();
            string redirectUrl;
            if ( IsRedirected(htmlContent , out redirectUrl) )
                return this.GetExternalPageData(redirectUrl);
            return this.Encoding.GetBytes(htmlContent);

    Best wishes,
    Radoslav Georgiev
    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
2 posts, 0 answered