AI OnAI Off
I am able to resolve my issue by adding the below line in content delete event and moving to trash event
ContentIndexer.Instance.Delete(e.Content);
So final working code is as follows
private void contentEvents_DeletingContent(object sender, ContentEventArgs e)
{
if (e.Content is IContent)
{
ContentIndexer.Instance.Delete(e.Content);
}
return;
}
Handling content moved to trash event
private void contentEvents_MovingContent(object sender, ContentEventArgs e)
{
if (e.Content is IContent && e.TargetLink.ID == 2)
{
ContentIndexer.Instance.Delete(e.Content);
}
return;
}
Hello,
I have an use case where we have EpiFind indexing job is running every night whcih indexes the content. An editor has deleted a page from content in the days time which should not be coming in search result when it is searched. But it is showing up in the result and when clicked on the result link it the page is not opening since it has been deleted/moved to trash.
I have tried with catching the delete event, moving page to trash where tried to remove the page entry from search index but still the deleted page is shown in result.
In the search query, I tried with applying filter to remove the deleted content by checking its parent link or IsDeleted property or even checked if it is under trash (ContentReference.WasteBasket) but haven't had any sucess.
Here is some code snippet that I tried -
In Epi find initialization event
public void Initialize(InitializationEngine context)()
{
// exclude deleted (inside recycle bin) or expired pages or unpublished pages
ContentIndexer.Instance.Conventions
.ForInstancesOf
.ShouldIndex(x => x.ContentLink.ID != ContentReference.WasteBasket.ID &&
!x.Ancestors().Contains(ContentReference.WasteBasket.ID.ToString()) &&
(x.StopPublish == null || x.StopPublish > DateTime.Now )&& x.StartPublish < DateTime.Now);
}
Handling content Deleting event
private void contentEvents_DeletingContent(object sender, ContentEventArgs e)(e.ContentLink.ID);
{
if (e.Content is IContent)
{
SearchClient.Instance.Delete
}
return;
}
Handling content moved to trash event
private void contentEvents_MovingContent(object sender, ContentEventArgs e)(e.ContentLink.ID);
{
if (e.Content is IContent && e.TargetLink.ID == 2)
{
SearchClient.Instance.Delete
}
return;
}
In the search page's controller
UnifiedSearchResults _SearchResults;
_SearchResults = searchClient.UnifiedSearch().For(queryString)(((IContent)x).ContentLink).Ancestors().In(new List { ContentReference.WasteBasket.ID.ToString() }))(((IContent)x).ContentLink).ParentLink.ID.Match(ContentReference.WasteBasket.ID))(((IContent)x).ContentLink).IsDeleted.Match(true))
.InField(x => ((VaxBasePageData)x).MetaKeywords)
.InField(x => ((VaxBasePageData)x).MetaTitle)
.InField(x => ((VaxBasePageData)x).MetaDescription)
.Filter(SiteFilterBuilder)
.Filter(x => !x.MatchTypeHierarchy(typeof(ImageData))).Filter(y => !y.MatchTypeHierarchy(typeof(ContainerPage)))
//.Filter(x=>!injectedLoader.Service.Get
//.Filter(x => !injectedLoader.Service.Get
.Filter(x => !injectedLoader.Service.Get
.Take(10).Skip((p - 1) * 10).GetResult(hitSpec, false);
I even tried with ExcludeDeleted() but no sucess with this as well.
Is there any way so that the deleted content can be excluded from search before the indexing job updates the result?
Can someone please help us in getting this resolved.
Thanks,
Kedar