Boolean
Use filters to narrow down search results, or use them for database-like queries. This topic explains how to filter search results based on boolean fields, with the Filter method in Episerver Find.
How it works
You can use the Filter method to filter boolean and nullable boolean fields in a couple of ways, as shown in the following list of use cases and examples.
Existence
To search for documents where a boolean field has a value, use the Exists method. The following search finds blog posts that has an Approved property with a value. In other words, 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 doesnt have an Approved property, use the following code.
var searchQuery = client.Search<BlogPost>()
.Filter(x => !x.Approved.Exists());
Matching true or false
For exact matching we can use the Match method. The following search matches blog posts whose Approved property is true. The LINQ equivalent would be Where(x => x.Approved).
var searchQuery = client.Search<BlogPost>()
.Filter(x => x.Approved.Match(true));
Last updated: Nov 16, 2015