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

Try our conversational search powered by Generative AI!

Need help with Episerver Find filters

Vote:
 

I have a search code as shown below that works fine. On the page where I show these result I have another content reference field that am displaying. I need to see if the search result contains the content reference item on the page and if so then remove it from the results.

Typically I can do a filter but the problem is that content reference can also be null so am not sure how to incorporate that null check.

foreach (var category in secondaryCategoryPages.Take(WebConstants.MaxMultiSearch))
{
multisearch = multisearch.Search<ContentArticlePage, SearchHitResult>(s => s
.FilterForVisitor()
.Skip((page - 1) * pageSize)
.Take(pageSize)
.OrderByDescending(x => x.ArticleDate)
.Select(x => ConvertFromIContent(x.ContentLink, category))
.StaticallyCacheFor(new TimeSpan(0, 5, 0)));
}

#216985
Feb 12, 2020 2:34
Vote:
 

Hi Dileep,

You could probably create an empty filter that essentially does nothing and then extend that to either do something, or not, depending on if the content reference is null or not.

I.E. -

var referenceFilter = multisearch.BuildFilter<ContentArticlePage>();

// I'm assuming you have access to the 'other' content reference you mentioned
if (contentReferenceItem != null)
{
    referenceFilter = referenceFilter.And(x => x.Field.Match(contentReferenceItem));
}

// Then add the filter into your existing search logic above 'FilterForVisitor()'
.Filter(referenceFilter)

Obviously, I don't know your exact code but hopefully the above will give you the gist of the idea.

Hope it helps!

- JJ

#217200
Feb 19, 2020 10:20
Vote:
 

Can you do something like

                query = query.Filter(x => CheckForContent(contentref) | contentref == null);
#217341
Feb 21, 2020 8:32
Vote:
 

Thanks for the inputs. Let me give it a try and will update and accept answer once I get it working.

#217767
Feb 29, 2020 19:14
James Johnson - Mar 05, 2020 8:47
Hi Dildeep,

Just wondering if you managed to get this working?
* 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.