November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hey Torunn, I found this: https://support.episerver.com/hc/en-us/articles/360001835651-How-to-filter-out-expired-content-in-Episerver-Search
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.
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.
For example in your Find Initialization module
ContentIndexerService.Service.Conventions.ForInstancesOf<PageData>().ShouldIndex(x => PublishedStateAssessorService.Service.IsPublished(x, PagePublishedStatus.Published));
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.
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.
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();
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.
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?