Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely Search & Navigation
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

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).

C#
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.

C#
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).

C#
var searchQuery = client.Search<BlogPost>()
    .Filter(x => x.Approved.Match(true));
Do you find this information helpful? Please log in to provide feedback.

Last updated: Nov 16, 2015

Recommended reading