How to ReIndex a built-in search index

Posted by Community Admin on 04-Aug-2018 14:00

How to ReIndex a built-in search index

All Replies

Posted by Community Admin on 13-Jul-2015 00:00

I have a 7.3 sitefinity project and I was dissecting the libraries with JustDecompile and came up with this class to pass in an Index name and then execute a Reindex just like if you would from the admin.  I'm wondering if anybody sees any issues with it.  Also i'm using Elmah but you could take that out if you want.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Sitefinity.BackgroundTasks;
using Telerik.Sitefinity.Publishing.Configuration;
using Telerik.Sitefinity.Publishing.Web.Services;
using Telerik.Sitefinity.Publishing.Web.Services.Data;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.SitefinityExceptions;
 
 
namespace SitefinityWebApp.CommonClasses
    public class ReindexSearchBackgroundTask : IBackgroundTask
    
        public string IndexName;
 
        public ReindexSearchBackgroundTask(string thisIndexName)
        
            IndexName = thisIndexName;
        
         
        public void Run(IBackgroundTaskContext context)
        
            SystemManager.RunWithElevatedPrivilege(new SystemManager.RunWithElevatedPrivilegeDelegate(this.RunTask));
 
        
        private void RunTask(object[] args)
        
            PublishingAdminService service = new PublishingAdminService();
            var points = service.GetPublishingPoints("SearchPublishingProvider", "LastModified", 0, 50, String.Empty);
            if (points != null && points.TotalCount > 0)
            
                foreach (var p in points.Items)
                
                    if (p.Title == IndexName)
                    
                        string searchIndexId = p.Id.ToString();
                        try
                        
                            service.ReindexSearchContent(PublishingConfig.SearchProviderName, searchIndexId);
                        
                        catch (System.IO.IOException ioEx)
                        
                            Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(ioEx.Message, ioEx.InnerException));
                        
                        catch (Exception ex)
                        
                            Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                        
                    
                
            
            
        
    

 

Posted by Community Admin on 18-Jul-2015 00:00

Something similar to this came up in the Sitefinity Devs group on G+. Here's a link to the discussion.

This thread is closed