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

Forums / Developing with Sitefinity / Search Index for Lists

Search Index for Lists

2 posts, 0 answered
  1. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    09 Sep 2010
    Link to this post
    I need a search index for lists. Will this be a custom search index I need to create? If so, can you point me towards how to do this?

    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Sep 2010
    Link to this post
    Hello mcpdinkansas,

    You have to create a custom index. Here is a sample code.

    provider

    usingSystem;
    usingSystem.Collections.Generic;
    usingSystem.Linq;
    usingSystem.Web;
    usingTelerik.Framework.Search;
    usingSystem.Collections;
       
    namespace Telerik.Samples.Search
    {
         
        public class ListsIndexProvider : IIndexingServiceClient
        {
            public ListsIndexProvider ()
            {
                 
            }
       
            #region IIndexingServiceClient Members
       
            public stringName
            {
                get{ return"ListsIndex"; }
            }
       
            public stringDescription
            {
                get{ return"Search Lists"; }
            }
       
            public string[] GetUrlsToIndex()
            {
                returnnewstring[0]; ;
            }
       
            public IIndexerInfo[] GetContentToIndex()
            {
                var manager = new ListManager();
                List<IIndexerInfo> list = newList<IIndexerInfo>();
       
                IList lists = manager.GetLists();
       
                foreach(INamedList namedList in lists)
                {
                    IList listItems = INamedList.Items;
                       
                    foreach(IListItem itm in listItems)
                    {
                       var url = "here construct the url to your list item";
                        IIndexerInfo listIndexInfo = new ListIndexerInfo(itm.ID, url);
                        list.Add(listIndexInfo);
                    }
                }
       
                returnlist.ToArray();
            }
           
       
            #endregion
       
           
               
        }
    }

    IndexerInfo

    usingSystem;
    usingSystem.Collections.Generic;
    usingSystem.Linq;
    usingSystem.Web;
    usingTelerik.Framework.Search;
    usingSystem.Text;
       
    namespace Telerik.Samples.Search
    {
       
        public class ListIndexerInfo : IIndexerInfo
        {
            public ListIndexerInfo(Guid itemID , string url)
            {
                this._postID = itemID;
                this.url = url;
            }
       
            #region IIndexerInfo Members
       
            publicstringPath
            {
                get{ returnthis.url; }
            }
       
            publicstringMimeType
            {
                get{ return"text/plain"; }
            }
       
            publicbyte[] GetData()
            {
                var mgr  = new ListManager();
                INamedList nl = mgr.GetList(postID);
                 // here you can use INamedList or ILIstItem and return the properties that will be indexed
                byte[] buffer = Encoding.GetBytes(string.Concat(nl.Name , " ",nk.Owner) );
                return buffer;
            }
       
            publicEncoding Encoding
            {
                get{ returnEncoding.UTF8; }
            }
       
            publicstringCulture
            {
                get{ returnstring.Empty; }
            }
       
            publicGuid ItemID
            {
                get{ returnthis.postID; }
            }
       
            #endregion
       
            #region Private variables
               
            private Guid _postID;
            private string url;
               
            #endregion
        }
    }


    Best wishes,
    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