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

Forums / Developing with Sitefinity / Custom Search Index - QueryString errors

Custom Search Index - QueryString errors

5 posts, 1 answered
  1. Brad
    Brad avatar
    28 posts
    Registered:
    20 Sep 2010
    06 Dec 2010
    Link to this post
    We have implemented a custom search index, such as below:

    public string[] GetUrlsToIndex()
    {
        List<RecipeItem> recipeList = new List<RecipeItem>();
        using (Entities ctx = new Entities())
        {
            var userRecipes = from r in ctx.Recipes
                              select r.ID;
            List<string> urls = new List<string>();
            string recipeDeatilsUrl = ConfigurationManager.AppSettings["RecipeDetailsURL"];
            foreach(Int64 rid in userRecipes)
            {
                urls.Add(String.Format("http://localhost:2003/Great-Meals-Recipes/Recipes/Details.aspx?rid={0}", rid.ToString()));
            }
            //int test = urls.ToArray<string>().Count();
            return urls.ToArray<string>();
        }
    }

    There are currently about 137 items that should be added (and this has been verified even within this method), but only one is being added. Looking at the cfs file generated in the App_Data/Search/All-Pages-and-Recipes/Index/_0.cfs data, it is only showing that the last ID is being searched, which is 212.

    Currently, the URLs generated are:

    http://localhost:2003/great-meals-recipes/recipes/details.aspx?rid=31 up through rid=212. Unfortunately, the only one being added to the index is rid=212, none of the others. Is this an issue with the search index itself, or should we be going around this a different way?

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Dec 2010
    Link to this post
    Hi Brad,

    You should have a custom class that inherits from IIndexerInfo. This class has a method GetData() - gets the content item data that should be parsed and indexed. Can you verify that you added all rids through this method.

    All the best,
    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. Brad
    Brad avatar
    28 posts
    Registered:
    20 Sep 2010
    06 Dec 2010
    Link to this post
    Hi Ivan,

    Are you mentioning the custom class that deals with the indexing itself, or our class that actually grabs the data itself and returns? Currently, we do not have a method utilizing GetData() anywhere.

    However, we have verified that all the URLs that should be indexed are being returned in the array itself, if that helps?

    Brad
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Dec 2010
    Link to this post
    Hi Brad,

    The id is added to the userRecipes but it looks like that it is not added to the index. You need a custom index that has its own IIndexerInfo class which implements the interface members.
    You can take a look at this webinar.

    Regards,
    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
    Answered
  5. Brad
    Brad avatar
    28 posts
    Registered:
    20 Sep 2010
    07 Dec 2010
    Link to this post
    Hey Ivan,

    Thank you for the link - watched the webinar, visited the sfwatch site notes that Gabe had created, and figured it out. We were trying to add URLs originally and have it index those automatically, but found out that by creating the classes needed, using the IIndexerInfo and returning only what we wanted is a much better solution. One tool I'd recommend that Gabe used and showed multiple times is the Lucene Luke app, helped a ton in finding the best way to output our searches.

    If anyone is interested in creating an index that uses QueryString URLs, we've found the best practice to be the following:

    In our IndexProvider.cs class: Notice the difference in using GetContentToIndex rather than GetUrlsToIndex
    public IIndexerInfo[] GetContentToIndex()
        {
            using (CMSEntities ctx = new CMSEntities())
            {
                var userRecipes = from r in ctx.Recipes
                                  select new { r.ID, r.recipeName, r.recipeDescription, r.recipeIngredients, r.recipeInstructions };
      
                var contentItems = new List<IIndexerInfo>();
                foreach (var rVar in userRecipes)
                {
                    var contentInfo = new CustomIndexerInfo();
                    contentInfo.Title = rVar.recipeName;
                    contentInfo.Description = rVar.recipeDescription;
                    contentInfo.Ingredients = rVar.recipeIngredients;
                    contentInfo.Instructions = rVar.recipeInstructions;
                    contentInfo.Url = string.Format("http://fulldomain.com/Great-Meals-Recipes/Recipes/Details.aspx?rid={0}", rVar.ID);
                    contentItems.Add(contentInfo);
                      
                }
                // Return content index
                return contentItems.ToArray();
            }
        }

    Using the GetData method, rather than GetURLs method, and creating a new class "CustomIndexerInfo.cs"

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Text;
    using Telerik.Framework.Search;
    namespace RecipeIndex
    {
        /// <summary>
        /// Summary description for CustomIndexerInfo
        /// </summary>
        public class CustomIndexerInfo : IIndexerInfo
        {
            public string Title { get; set; }
            public string SubmittedBy { get; set; }
            public string Description { get; set; }
            public string Ingredients { get; set; }
            public string Instructions { get; set; }
            public string Url { get; set; }
      
      
            public CustomIndexerInfo()
            {
                //
                // TODO: Add constructor logic here
                //
            }
      
            public string Culture
            {
                //get { throw new NotImplementedException(); }
                get { return string.Empty; }
            }
      
            public System.Text.Encoding Encoding
            {
                //get { throw new NotImplementedException(); }
                get { return Encoding.UTF8; }
            }
      
            public byte[] GetData()
            {
                //throw new NotImplementedException();
                string text = "<title>" + Title + "</title>" +
                    Description + Ingredients + Instructions;
                return Encoding.GetBytes(text);
            }
      
            public Guid ItemID
            {
                //get { throw new NotImplementedException(); }
                get { return Guid.Empty; }
            }
      
            public string MimeType
            {
                //get { throw new NotImplementedException(); }
                get { return "text/html"; }
            }
      
            public string Path
            {
                get { return Url; }
            }
      
            public string ResolveIndexPath()
            {
                //throw new NotImplementedException();
                return Path;
            }
        }
    }

    Thanks again, Ivan.
Register for webinar
5 posts, 1 answered