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 enum and nullable enum fields in a couple of ways, as shown in the following cases and examples.

Note: Currently, there is support only for filtering by exact matching of values for enums. That is, bitwise comparison for enum types that have the Flags attribute is not baked into the Match method but has to be done explicitly.

Matching by value

For exact matching,  use the Match method. The following search matches blog posts whose PublishState property is a specific enum value. The LINQ equivalent is Where(x => x.PublishState == PublishState.Published).

C#
var searchQuery = client.Search<BlogPost>()
    .Filter(x => x.PublishState.Match(PublishState.Published));

Existence

To search for documents where an enum field has a value, we can use the Exists method. The following search finds blog posts that has an Approved property with a value. In other words, the following code is similar to the LINQ query Where(x => x.PublishState.HasValue).

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

Last updated: Nov 16, 2015

Recommended reading