Try our conversational search powered by Generative AI!

Find returning Expired content


Episerver v11.12.0 hosted at Episerver Azure

I am using FIND to list specific blocks that I pull from a folder.  However, the search included blocks that are marked Expired.  I am using the extensions CurrentlyPublished().FilterForVisitor().ExcludeDeleted().  I have several other parameters I'm adding to the search.  Is it possible I'm loading adding them in the wrong order?

var query = SearchClient.Instance.Search<ArticlePage>();
query = query.Filter(y => y.Ancestors().Match(insightsPage.PageLink.ID.ToString()));

if (!string.IsNullOrEmpty(queryString))
    query = query.For(queryString, q =>
            q.Query = $"*{q.Query}*";
            q.Boost = 2;
            q.DefaultOperator = EPiServer.Find.Api.Querying.Queries.BooleanOperator.And;

var filterBuilder = SearchClient.Instance.BuildFilter<IInsightPage>().FilterOnCurrentSite()

if (categories != null && categories.Any()) {
    foreach (var category in categories)
        filterBuilder = filterBuilder.And(x => x.SearchCategories().Match(category));

    query = query.Filter(filterBuilder);

query = query.OrderBy(page => page.Heading);

var results = query.GetContentResult();
Edited, Dec 24, 2019 17:41

Hi Eric,

Daniel mention this is a bug in earlier versions of Find but it is fixed in Find 12 (Link). So try to update your find version or try below solution if the upgrade is not an option.

Please try this-

private bool IsPublished(IVersionable content)
     if (content == null) 
        return true; 
     if (content.StopPublish > DateTime.UtcNow) 
        return content.Status.HasFlag(VersionStatus.Published); 

     return false; 
Edited, Dec 24, 2019 19:28

Hi Eric, your sample code only uses the filterbuilder if there are categories. If there are no categories then no filtering is done.

Dec 30, 2019 10:30

Code bug.  Not an Episerver issue.  Thanks for pointing that out Antti

Feb 06, 2020 18:25
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.