Use filters to narrow down search results or for database-like queries. This topic explains how to filter search results based on boolean fields, with the Filter method in Episerver Find.
You can use the Filter method to filter boolean and nullable boolean fields in a couple of ways, as shown in the following use cases and examples.
To search for documents where a boolean field has a value, use the Exists method. The following search finds blog posts that have an Approved property with a value. The below code is similar to the LINQ query Where(x => x.Approved.HasValue).
var searchQuery = client.Search<BlogPost>() .Filter(x => x.Approved.Exists());
You can negate the filter with an exclamation mark (!); to instead find all blog posts that lack an Approved property, use the following code.
var searchQuery = client.Search<BlogPost>() .Filter(x => !x.Approved.Exists());
For exact matching, use the Match method. The following search matches blog posts whose Approved property is true. The LINQ equivalent is Where(x => x.Approved).
var searchQuery = client.Search<BlogPost>() .Filter(x => x.Approved.Match(true));
Last updated: Oct 31, 2016