Try our conversational search powered by Generative AI!

EPi Find : Exclude deleted content from Search results

Vote:
 

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)
{
if (e.Content is IContent)
{
SearchClient.Instance.Delete(e.ContentLink.ID);
}

return;
}

Handling content moved to trash event

private void contentEvents_MovingContent(object sender, ContentEventArgs e)
{
if (e.Content is IContent && e.TargetLink.ID == 2)
{
SearchClient.Instance.Delete(e.ContentLink.ID);
}

return;
}

In the search page's controller

UnifiedSearchResults _SearchResults;

_SearchResults = searchClient.UnifiedSearch().For(queryString)
.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(((IContent)x).ContentLink).Ancestors().In(new List { ContentReference.WasteBasket.ID.ToString() }))
//.Filter(x => !injectedLoader.Service.Get(((IContent)x).ContentLink).ParentLink.ID.Match(ContentReference.WasteBasket.ID))
.Filter(x => !injectedLoader.Service.Get(((IContent)x).ContentLink).IsDeleted.Match(true))
.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

#195455
Jul 25, 2018 12:54
Vote:
 

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;
}

#195458
Jul 25, 2018 13:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.