A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Issue with Applying filter on null content

Vote:
 

I have an EPI find query as below

multisearch = multisearch.Search<GenericPage, SearchHitResult>(s => s
.FilterForVisitor()
.Filter(f => !f.ContentLink.Match(ContentToFilter.ContentLink))
.Skip((page - 1) * pageSize)
.Take(pageSize)
.OrderByDescending(x => x.ArticleDate)

The ContentToFilter is a Page type which I get using content loader as shown below:

_contentLoader.TryGet<IContent>(optionalContent, out var ContentToFilter);

There is a possibility that TryGet will result in null and then the filter line will throw exception. How do I check for null content before applying this filter. 

#207618
Sep 26, 2019 20:37
Vote:
 

Hi Dileep,

TryGet will return the result as Ture or False so you can get in any variable then check it with if condition.

var searchQuery = this._client.Search<T>();
var value= _contentLoader.TryGet<IContent>(optionalContent, out var ContentToFilter);

if(value)
{
      searchQuery = searchQuery.Filter(f => !f.ContentLink.Match(ContentToFilter.ContentLink))
}

Then apply the other logic.

Hope it helps

Thanks

Ravindra S. Rathore

#207623
Sep 27, 2019 7:53
Dileep D - Sep 27, 2019 19:25
Straight and simple. Thanks!

Is there a way to have this specific thing done using a buildfilter?
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.