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

Forums / General Discussions / Search Forum Module

Search Forum Module

4 posts, 0 answered
  1. WhiteShark
    WhiteShark avatar
    10 posts
    Registered:
    26 Sep 2012
    01 Oct 2010
    Link to this post
    Is there built-in Search function for Forum Module? if yes, where can I find it? Can you someone provide code to search for Forum module?

    thanks,
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Oct 2010
    Link to this post
    Hi WhiteShark,

    There is no built in search provider for forums. I created a sample for you that will index forum items.

    IndexProvider

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Framework.Search;
    using System.Collections;
     
    namespace Telerik.Forums.Search
    {
        /// <summary>
        /// Summary description for ForumIndexProvider
        /// </summary>
        public class ForumIndexProvider : IIndexingServiceClient
        {
     
            #region IIndexingServiceClient Members
     
            public string Name
            {
                get { return "ForumIndex"; }
            }
     
            public string Description
            {
                get { return "Search Forum posts"; }
            }
     
            public string[] GetUrlsToIndex()
            {
                return new string[0]; ;
            }
     
            public IIndexerInfo[] GetContentToIndex()
            {
                ForumManager manager = new ForumManager();
                List<IIndexerInfo> list = new List<IIndexerInfo>();
     
                IList forums = manager.GetForums(excludeHiddenForums);
     
                foreach (IForum forum in forums)
                {
                    IList posts = forum.Posts;
                     
                    foreach (IPost post in posts)
                    {
                        Guid threadID = post.Thread == null ? post.ID : post.Thread.ID;
                        string forumUrl = string.Concat(singleThreadPage, "?mode=singleThread&thread=", threadID);
                        IIndexerInfo fileIndexInfo = new ForumIndexerInfo(post.ID, forumUrl);
                        list.Add(fileIndexInfo);
                    }
                }
     
                return list.ToArray();
            }
     
            public void Initialize(IDictionary<string, string> settings)
            {
                excludeHiddenForums = Convert.ToBoolean(settings[FORUM_SETTING_EXCLUDE_HIDDEN_FORUMS]);
                singleThreadPage = settings[FORUM_SETTING_SINGLE_THREAD_PAGE];
            }
     
            public event EventHandler<IndexEventArgs> Index;
     
            #endregion
     
            private bool excludeHiddenForums;
            private string singleThreadPage;
     
            public const string FORUM_SETTING_EXCLUDE_HIDDEN_FORUMS = "excludeHiddenForums";
            public const string FORUM_SETTING_SINGLE_THREAD_PAGE = "singleThreadPage";
             
        }
    }

    IndexerInfo class

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Framework.Search;
    using System.Text;
     
    namespace Telerik.Forums.Search
    {
        /// <summary>
        /// Summary description for ForumIndexerInfo
        /// </summary>
        public class ForumIndexerInfo : IIndexerInfo
        {
            public ForumIndexerInfo(Guid postID, string url)
            {
                this.postID = postID;
                this.url = url;
            }
     
            #region IIndexerInfo Members
     
            public string Path
            {
                get { return this.url; }
            }
     
            public string MimeType
            {
                get { return "text/plain"; }
            }
     
            public byte[] GetData()
            {
                ForumManager forumManager = new ForumManager();
                IPost post = forumManager.GetPost(postID);
                byte[] buffer = Encoding.GetBytes(string.Concat(post.Content , " " ,post.Owner) );
                return buffer;
            }
     
            public Encoding Encoding
            {
                get { return Encoding.UTF8; }
            }
     
            public string Culture
            {
                get { return string.Empty; }
            }
     
            public Guid ItemID
            {
                get { return this.postID; }
            }
     
            #endregion
     
            #region Private variables
             
            private Guid postID;
            private string url;
             
            #endregion
        }
    }

    You could take a look at Working with Sitefinity search and Bonus track - implementing custom index for products module

    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
  3. Taha Zouhair
    Taha Zouhair avatar
    10 posts
    Registered:
    22 Aug 2013
    03 Apr 2015
    Link to this post

    Hello,

     I'm running a Sitefinity 7 site but could not find the following classes in the DLLs:
    IIndexingServiceClient and IIndexerInfo

     

    Anywhere where I can find a more updated documentation on this?
    Thanks

  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Nov 2016
    08 Apr 2015
    Link to this post
    Hello Taha,

    The sample below is for version 3.x

    In order to achieve your need in your version you can use the build-in functionality by creation of Search index for Forum posts.

    More information is available here.


    I hope this helps.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
Register for webinar
4 posts, 0 answered