Try our conversational search powered by Generative AI!

Remove expired page data from search results


Hi, I use a Find query on few different page types to retrieves Episerver.Find.SearchResults type data set. The results contain the pages that are 'Expired'. I simply need to remove the 'Expired' pages from the results.

1. Can we avoid indexing 'Expired' pages?

2. How to remove 'Expired' pages from the index? Or

3. How to remove 'Expired' pages from query results?

I tried 'SkipWhile' on the Results, but then it returned no values.

I also tried to add a query filter with 'page.CheckPublishedStatus(PagePublishedStatus.Published)', but it also returned no values.

I believe there must be ab simple easy way to do this. Please help. 

Nov 11, 2015 7:57

Have you tried adding .FilterForVisitor() to your search query? This should take care of this.

Nov 11, 2015 8:16

Thanks for the quick reply. 

I tried to add FilterForVisitor() in the query and getting this error;

'ISearch<SearchResult>' does not contain a definition for 'FilterForVisitor' and no extension method 'FilterForVisitor' accepting a first argument of type 'ISearch<SearchResult>' could be found 

are there any examples of the usage of this filter? 

Nov 11, 2015 11:32

It will only work for IContent. Here is the documentation:

Perhaps you could post your query

Nov 11, 2015 12:51

I use initialization module to delete expired or deleted pages (inside recycle bin):

public class EpiFindInitializationModule : IInitializableModule
    private IContentEvents _contentEvents;
    private IContentEvents ContentEvents
        get { return _contentEvents ?? (_contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>()); }

    public void Initialize(InitializationEngine context)
        ContentEvents.SavedContent += ContentEvents_SavedContent;

        // exclude deleted (inside recycle bin) or expired pages
                        .ShouldIndex(x => x.ContentLink.ID != ContentReference.WasteBasket.ID &&
                                        !x.Ancestors().Contains(ContentReference.WasteBasket.ID.ToString()) &&
                                        x.StopPublish > DateTime.Now);

    private void ContentEvents_SavedContent(object sender, EPiServer.ContentEventArgs e)
        var page = e.Content as PageData;
        // delete expired page
        if (page != null && page.StopPublish <= DateTime.Now)
            SearchClient.Instance.Delete<PageData>(x => x.PageLink.Match(page.PageLink));

    public void Preload(string[] parameters) { }

    public void Uninitialize(InitializationEngine context)
        ContentEvents.SavedContent -= ContentEvents_SavedContent;

And a scheduled job that calls:

SearchClient.Instance.Delete<PageData>(x => x.StopPublish.Before(DateTime.Now))
Edited, Nov 11, 2015 14:48

I'm trying using FilterForVisitor() with no success. I'm still having the expired content in results. Does Find update the index when a user sets expiration on a page in editor mode?

Edited, Jan 26, 2017 11:07

Maybe run scheduled job and reindex?

Jan 26, 2017 11:24

Should I reindex the whole website everytime a single page expires?! That's nonsense... I was hoping that Find has some functionality which removes pages from index if they expire...

Jan 26, 2017 11:35

It should remove those from index automatically from what I gather with newer versions of Find at least. I know there was a bug with files for expired pages but that was fixed in Episerver Find 12. So I would try running the scheduled job once and see if it works automatically after that. 

Jan 26, 2017 16:18
* 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.