Programmatically remove an item from Examine Index on unpublish
I have a bit of a weird issue on a 4.7 site whereby a page is unpublished it occassionally remains in the examine index and appears in search results. This can be fixed by reindexing the site but as the site is quite large it isn't really a viable solution to manually reindex every time a problem is reported with search..
I was thinking of perhaps having an event handler fire after unpublish to remove the index entry but I'm not sure if this is the best way to get around this problem.
Has anyone come across this issue / got a fix for it?
class RemoveIndexOnUnpublishEventHandler : ApplicationBase { public RemoveIndexOnUnpublishEventHandler() { Document.BeforeUnPublish += new Document.UnPublishEventHandler(Document_BeforeUnPublish); }
void Document_BeforeUnPublish(Document sender, umbraco.cms.businesslogic.UnPublishEventArgs e) { var Nodes = sender.DescendantsAndSelf();
foreach (BaseIndexProvider indexer in ExamineManager.Instance.IndexProviderCollection) { foreach (var Page in Nodes) { indexer.DeleteFromIndex(Page.Id.ToString()); } } } }
This event handler gets all the children of the page that has been unpublished and removes their entries from the search indexes.
Programmatically remove an item from Examine Index on unpublish
I have a bit of a weird issue on a 4.7 site whereby a page is unpublished it occassionally remains in the examine index and appears in search results. This can be fixed by reindexing the site but as the site is quite large it isn't really a viable solution to manually reindex every time a problem is reported with search..
I was thinking of perhaps having an event handler fire after unpublish to remove the index entry but I'm not sure if this is the best way to get around this problem.
Has anyone come across this issue / got a fix for it?
Thank!
I've gone for an event handler to fix this issue.
This event handler gets all the children of the page that has been unpublished and removes their entries from the search indexes.
is working on a reply...