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

Forums / Developing with Sitefinity / Programmatically starting the search index

Programmatically starting the search index

4 posts, 0 answered
  1. David
    David avatar
    26 posts
    Registered:
    12 Jul 2008
    14 Apr 2009
    Link to this post
    Hi,

    I have written a handler to programmatically index my site:

    using System.Collections.Generic;
    using System.Web;
    using Telerik.Search.Engine;

    public class SearchIndexer : IHttpHandler
    {   
        public void ProcessRequest (HttpContext context)
        {
            foreach (KeyValuePair<string, IIndexingService> pair in IndexingManager.IndexingServices)
            {
                IndexingManager.StartIndexing(pair.Value, false);
            }
            
            context.Response.ContentType = "text/plain";
            context.Response.Write("Indexing done");
        }
     
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    This seems to work but I would like to know if anyone can see any issues with it. Also, is this the best way of solving this issue? I plan on running this script every few minutes and it takes a few seconds to complete so anything I can do to improve it will help.

    Thanks
    Dave Cooper

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    16 Apr 2009
    Link to this post
    Hello David,

    As I see it your code runs one after the another. The problem you could face is related to the time of indexing if your Indexes become too large. But, if it works good for your keep it as original. Another thing that you could try is specifying the index. You could create a method with indexName as parameter
    public void StartIndex(string indexName) and then call it. Thus, you can run them separately.

    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.
  3. David
    David avatar
    26 posts
    Registered:
    12 Jul 2008
    16 Apr 2009
    Link to this post
    Thank you for your reply. I will bear in mind the issue you highlighted. If the indexing starts to take too long I suppose I could create an indexer for each index so that they can have their own thread and different schedules.

    For now though the above seems to work pretty well.

    Thanks
    Dave Cooper
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    16 Apr 2009
    Link to this post
    Hello David,

    Another way is working with webservices instead of the handler, but it will be more complicated that your method.

    Best wishes,
    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.
Register for webinar
4 posts, 0 answered