Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Boolean

Filter search results based on Boolean fields, with the Filter method in Optimizely Search & Navigation .

Use filters to narrow down search results or for database-like queries. 

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.

Exists

To search for documents where a Boolean field has a value, use the Exists method. The following search finds blog posts with an Approved property with a value. The following 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 point (!). To find blog posts that lack an Approved property, use the following code.

var searchQuery = client.Search<BlogPost>()
    .Filter(x => !x.Approved.Exists());

True or false

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