How to ReIndex a built-in search index
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);
Something similar to this came up in the Sitefinity Devs group on G+. Here's a link to the discussion.