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

Forums / Bugs & Issues / Search Index for Blogs indexes future dated posts

Search Index for Blogs indexes future dated posts

2 posts, 0 answered
  1. Leonard
    Leonard avatar
    19 posts
    Registered:
    01 Dec 2005
    19 Jul 2010
    Link to this post

    I noticed the search index for blogs (BlogIndex) includes future-dated blog posts. Is this the intended behaviour?

    [version: CE 3.7 SP3]
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 Jul 2010
    Link to this post
    Hello Leonard,

    Yes, the index gets all posts. This is a bug in standard and CE as well. There is a workaround  which requires to create a new index for blogs. There GetUrlsToIndex and GetContentToIndex methods should be overridden.

    below is the code

    BlogIndexProviderCustom

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Blogs;
    using System.Globalization;
    using Telerik.Framework.Search;
    using System.Collections;
    using Telerik.Cms.Engine;
    using Telerik.Web;
     
    /// <summary>
    /// Summary description for BlogIndexProviderCustom
    /// </summary>
    public class BlogIndexProviderCustom : ContentIndexProvider
    {
        public BlogIndexProviderCustom()
        {
        }
     
        public override string Name
            {
                get { return "BlogIndexProviderCustom"; }
            }
     
            /// <summary>
            /// Provides detailed description of the provider.
            /// </summary>
            public override string Description
            {
                get { return "BlogIndexProvider"; }
            }
     
            /// <summary>
            /// Gets the content item key implicitly. This property should be overriden in the
            /// derived classes so that 2 different controls deriving from this one can be used together.
            /// </summary>
            /// <value>The content item key implicitly.</value>
            protected override string ContentItemKeyImpl
            {
                get
                {
                    return BlogManager.BlogItemKey;
                }
            }
     
            /// <summary>
            /// Gets the content provider key implicitly. This property should be overriden in the
            /// derived classes so that 2 different controls deriving from this one can be used together.
            /// </summary>
            /// <value>The content provider key implicitly.</value>
            protected override string ContentProviderKeyImpl
            {
                get
                {
                    return BlogManager.BlogProviderKey;
                }
            }
     
            /// <summary>
            /// Gets the name of the default blogs data provider.
            /// </summary>
            /// <returns>The name of the default blogs data provider.</returns>
            protected override string GetDefaultContentProvider()
            {
                return BlogManager.DefaultContentProvider;
            }
     
            /// <summary>
            /// Gets the filter expression
            /// </summary>
            public override string FilterExpression
            {
                get
                {
                    return "Title='InVariantCulture';";
                }
            }
     
            public string  BlogPublicationDate
            {
                get
                {
                    return "Publication_Date <='" + DateTime.Now + "';";
                }
            }
     
        public override Telerik.Framework.Search.IIndexerInfo[] GetContentToIndex()
        {
            if (this.retrievalMethod != RetrievalMethod.Direct)
                return new IIndexerInfo[0];
     
            if (this.manager == null)
                throw new InvalidOperationException("NotInitialized");
     
     
            IList list = this.manager.GetContent(0, 0, String.Empty, ContentStatus.Published, this.ParentIDs, this.BlogPublicationDate);
            List<IContent> lst = new List<IContent>();
            foreach (IContent cnt in list)
            {
                if (!lst.Contains(cnt))
                    lst.Add(cnt);
            }
            List<IIndexerInfo> data = new List<IIndexerInfo>(lst.Count);
            foreach (IContent content in lst)
            {
                if (content != null)
                {
                    if (this.manager.Provider.AllowLocalization)
                    {
                        foreach (string lng in content.Languages)
                        {
                            CultureInfo cult = CultureInfo.GetCultureInfo(lng);
                            string path = this.GetItemUrl(content, this.baseUrl, cult);
                            data.Add(this.GetIndexerInfo(path, content, cult));
                        }
                    }
                    else
                    {
                        string path = this.GetItemUrl(content, this.baseUrl, null);
                        data.Add(this.GetIndexerInfo(path, content));
                    }
                }
            }
            return data.ToArray();
        }
     
        public override string[] GetUrlsToIndex()
        {
            if (this.retrievalMethod != RetrievalMethod.WebRequest)
                return new string[0];
     
            if (this.manager == null)
                throw new InvalidOperationException("NotInitialized");
     
            IList data = this.manager.GetContent(0, 0, String.Empty, ContentStatus.Published, this.ParentIDs, this.BlogPublicationDate);
            List<string> urls = new List<string>(data.Count);
            for (int i = 0; i < data.Count; i++)
            {
                if (this.manager.Provider.AllowLocalization)
                {
                    IContent content = (IContent)data[i];
                    foreach (string lng in content.Languages)
                    {
                        content.Language = lng;
                        urls.Add(UrlPath.ResolveAbsoluteUrl(this.GetItemUrl(content, this.baseUrl, CultureInfo.GetCultureInfo(lng))));
                    }
                }
                else
                {
                    urls.Add(UrlPath.ResolveAbsoluteUrl(this.GetItemUrl((IContent)data[i], this.baseUrl, null)));
                }
            }
            return urls.ToArray();
        }
    }

    BlogsIndexSettings control

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Framework.Search;
    using System.Web.UI.WebControls;
     
    /// <summary>
    /// Summary description for BlogsIndexSettings
    /// </summary>
    public class BlogsIndexSettings : CompositeControl, ISettingsControl
    {
        public BlogsIndexSettings()
        {
            //
            // TODO: Add constructor logic here
            //
        }
     
        #region ISettingsControl Members
     
        public void InitSettings(IDictionary<string, string> indexSettings)
        {
        }
     
        public IDictionary<string, string> GetSettings()
        {
            return new Dictionary<string, string>();
        }
     
        #endregion
    }

    BlogsSettingsControl

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Framework.Search;
    using System.Web.UI.WebControls;
     
    /// <summary>
    /// Summary description for BlogsSettingsControl
    /// </summary>
    public class BlogsSettingsControl : CompositeControl, ISearchViewControl
    {
        public BlogsSettingsControl()
        {
          
        }
     
        #region ISearchViewControl Members
     
        public void InitializeSettings(IDictionary<string, string> indexSettings)
        {
     
        }
     
        #endregion
    }

    web.config registration

    <indexClients>
                    <add name="PageIndex" type="Telerik.Cms.Search.PageIndexProvider, Telerik.Cms" settingsControl="Telerik.Cms.Web.UI.PageIndexSettings, Telerik.Cms" viewSettingsControl="Telerik.Cms.Web.UI.SearchViewControl, Telerik.Cms" description="Provides indexing services for CMS Pages." />
                     
            <add name="BlogIndexProviderCustom" type="BlogIndexProviderCustom, App_Code" settingsControl="BlogsIndexSettings, App_Code" viewSettingsControl="BlogsSettingsControl, App_Code" description="Provides indexing services for Blogs" />
             
                </indexClients>


    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
2 posts, 0 answered