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

Forums / Developing with Sitefinity / Custom Blog index provider

Custom Blog index provider

2 posts, 0 answered
  1. Annie
    Annie avatar
    123 posts
    Registered:
    08 Apr 2009
    28 Jul 2009
    Link to this post
    Hi,

    I need to create  a custom blog index provider, Do you have any sample code for the blog index provider that I can modify

    Thank you
    Annie
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    28 Jul 2009
    Link to this post
    Hi Annie,

    Below is a bare bone code of implementing custom index.

    1. Create SettingsControl

        public class CustomBlogsViewSettingsControl : CompositeControl, ISearchViewControl 
        { 
            public CustomBlogsViewSettingsControl () 
            { 
            } 
            #region ISearchViewControl Members 
     
            public void InitializeSettings(IDictionary<stringstring> indexSettings) 
            { 
     
            } 
            #endregion 
        } 

    2. Create IndexingSettings class

        public class CustomBlogIndexSettings : CompositeControl, ISettingsControl 
        { 
            public FileIndexSettings() 
            { 
                // 
                // TODO: Add constructor logic here 
                // 
            } 
            #region ISettingsControl Members 
     
            public void InitSettings(IDictionary<stringstring> indexSettings) 
            { 
                 
            } 
     
            public IDictionary<stringstring> GetSettings() 
            { 
                return new Dictionary<stringstring>(); 
            } 
            #endregion 
        } 

    3. Create an IndexingProvider that inherits from IIndexingServiceClient. Here you can also override GetItemUrl to get direct access to contentItem and SingleItem.

    public class CustomBlogsIndexProvider : IIndexingServiceClient 
        { 
     
            public override string Name 
            { 
                get { return "CustomBlogsIndex"; } 
            } 
     
             
            public override string Description 
            { 
                get { return "some description"; } 
            } 
            public string[] GetUrlsToIndex() 
            { 
                return new string[0]; 
            } 
                      
            public IIndexerInfo[] GetContentToIndex() 
               { 
                              ContentManager manager = new ContentManager("Blogs"); 
                              List<IIndexerInfo> list = new List<IIndexerInfo>(); 
                 
                              IList files = manager.GetContent(); 
     
                              foreach (IContent file in files) 
                              { 
                                      // do something with your content 
                              } 
     
                 
                      return list.ToArray(); 
               } 
     
            
            
             public void Initialize(IDictionary<stringstring> settings) 
               { 
                         // initialize settings 
               } 
     
             public event EventHandler<IndexEventArgs> Index; 
                   #endregion 
     
             
        } 

    4. Finally you can create IndexerInfo class.

        public class CustomBlogsIndexerInfo : IIndexerInfo 
        { 
            public CustomBlogsIndexerInfo(string url, Guid itemId, CultureInfo culture) 
            { 
                this.url = url; 
                this.itemId = itemId; 
                this.culture = (culture != null ? culture.Name : string.Empty); 
            } 
            #region Private fields 
     
            private string url; 
            private Guid itemId; 
            private string culture; 
            private static readonly object syncObject = new object(); 
            #endregion 
            #region IIndexerInfo Members 
     
            public string  Path 
            { 
                get { return this.url; } 
            } 
     
            public byte[]  GetData() 
            { 
                if (HttpContext.Current == null
                    throw new InvalidOperationException(); 
     
               // add logic here 
            } 
     
            public Encoding  Encoding 
            { 
                get { return Encoding.UTF8; } 
            } 
     
            public string  Culture 
            { 
                get { return this.culture; } 
            } 
     
            public Guid  ItemID 
            { 
                get { return this.itemId; } 
            } 
            #endregion 
        } 


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