Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

How to filter expired content

Vote:
 

Hi!

We are experiencing that expired content shows up in the search result. We tried applying filterforvisitor, like shown below, but it didn't work. How can we filter out the expired content?

var visitorFilter = _findClient.BuildFilter<PageData>().FilterForVisitor();

var result = query.Filter(visitorFilter).SortBy(request.SortBy)
                              .Skip(skip)
                              .Take(pageSize)
                              .ApplyBestBets()
                              .FuzzyMatch(request.Query, x => x.Heading)
                              .FuzzyMatch(request.Query, x => x.MainIntro)
                              .GetContentResult();
#204020
May 16, 2019 13:32
Vote:
 

Hi,
I notice that the title of the article is "How to filter out expired content in Episerver Search," so I'm not sure if it applies to Find. Please let us know if that works with Find, Torunn.

#204043
May 16, 2019 18:46
Vote:
 

What we do for expiired content is remove it from the index so that the index is smaller. That way it never appears in search, you can do that with the Episerver Find conventions.

#204059
May 17, 2019 11:22
Vote:
 

For example in your Find Initialization module

ContentIndexerService.Service.Conventions.ForInstancesOf<PageData>().ShouldIndex(x => PublishedStateAssessorService.Service.IsPublished(x, PagePublishedStatus.Published));
#204060
May 17, 2019 11:24
Vote:
 

Hi Torunn,

As far as I'm aware, FilterForVisitor() should remove expired content but, if it's not working as expected perhaps you could add in a filter to remove expired content like this:

Filter(x => !x.StopPublish.Before(DateTime.Now))

Does the expired content eventually disappear or does it just remain in the results? Find has some caching on results returned by GetContentResult() so I wonder if the issue is related to that?

@Scott - Did that approach work for you? I tried a similar approach on my first Find project and it didn't work out quite as I'd hoped. When a content item expires, it triggers a reindex of that content but, if the search conventions prevent that reindexing, the content remains in the index but in the state it was in just before it expired. It's only then removed by a clear and rebuild of the index.

#204076
May 17, 2019 19:45
Vote:
 

Yes it's working fine for us, the we use it across commerce and cms items and it's working like a charm. The only downside is that removing items from the index also means if you're using find for the CMS search they don't appear in there but as we have over 50,000 commerce items dynamically from 2 different integration points we decided keeping it clean was a good idea.

#204108
May 20, 2019 9:33
Vote:
 

Thanks everyone. The filterforvisitor doesn't work. It is unfortunate to remove the expired content from the index, as it won't show up in the cms search, as Scott pointed out. 
This became the solution for me:

query = query.FilterHits(x => !(((PageData) x).StopPublish.Before(DateTime.Now)));

var query = _findClient.Search<ISearchableContent>(findLang)
.ApplyQueriedSearch(request.Query)
.ApplyCommonFilters()
.TermsFacetFor(x => x.SearchSection.Value);

query = query.FilterHits(x => !(((PageData) x).StopPublish.Before(DateTime.Now)));

var result = query.SortBy(request.SortBy)
.Skip(skip)
.Take(pageSize)
.ApplyBestBets()
.FuzzyMatch(request.Query, x => x.Heading)
.FuzzyMatch(request.Query, x => x.MainIntro)
.GetContentResult();
#204167
May 21, 2019 10:30
Vote:
 

Great, yes it's a shame. Personally I'd really like it if we could have different buckets we could target for things like this, I'd really love to be able to control what's index more granular so I could have a CMS bucket for everything and filtered buckets for each of my searches.

#204169
May 21, 2019 10:41
Vote:
 

I'd suggest to go with DateTime.UtcNow, instead of .Now

Also you should care about StartPublish as well 

#204219
May 22, 2019 16:13
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.