sitefinity

Sitefinity search index scope - add ihttphandler task


Is there is a way I can add an ihttphandler to the search index scope. I have a ihttphandler processrequest that collecting external data and then doing an updateIndex. But I wanted to see if I can trigger that when the re-index task is completed.

 public class ExternalIndexerHandler : IHttpHandler

Solution

  • So I think you want to run your custom code on the ToPublishingPoint method, when it's done right?

    Global.asax

                PublishingSystemFactory.UnregisterPipe(PageInboundPipe.PipeName);
                PublishingSystemFactory.RegisterPipe(PageInboundPipeCustom.PipeName, typeof(PageInboundPipeCustom));
    

    Now the pipe...

        public class PageInboundPipeCustom : PageInboundPipe
        {
            public override void ToPublishingPoint()
            {
                //Index has completed, time to do whatever now...
                base.ToPublishingPoint();
    
                var itemsToAdd = new List<WrapperObject>();
    
                //Make sure its only running for a specific index
                if (this.PipeSettings.PublishingPoint.Name == "YourIndexName")
                {
                    var externalStuff = this.GetExternalStuff();
                    foreach (var s in externalStuff )
                    {
                        var item = new AppendixIndexItem(s);
                        var itemToAdd = new WrapperObject(item);
    
                        Debug.WriteLine(item.IdentityField);
    
                        //Metadata... if needed
                        //itemToAdd.SetOrAddProperty("Tags", "Educational Material");
                        itemsToAdd.Add(itemToAdd);
                    }
    
                    if (itemsToAdd.Count > 0)
                    {
                        this.PublishingPoint.AddItems(itemsToAdd);
                    }
                }
            }
    
            public List<string> GetExternalStuff() {
               var items = new List<string>();
               
               //Callback to your external stuff?
    
               return items;
            }
        }
    
    

    Is that what you're looking for?

    Steve McNiven-Scott