Area: Optimizely Search & Navigation
Applies to versions: 12 and higher
Other versions:

Filter facets

Recommended reading 

Facets are used for grouping documents based on some criteria, for example specific terms or date range. This topic explains how facets based on filters are used in Optimizely Search & Navigation.

How it works

A filter facet returns a count of all search results that match a filter. The filter can be an expression, as used with the Filter method, so can range from a single criterion to very complex criteria made up of multiple sub criteria.

To request a filter facet, use the FilterFacet method, which has two parameters: name and filter or filter expression. You retrieve the resulting facet from the search results object using a method with the same name but with only a name parameter. The returned object has a single property, Count, which is the number of documents that match the search query and filter.


The following example shows a sample search for all products which requests, and retrieves the value from, two filter facets.

var result = client.Search<Product>()
  .FilterFacet("In stock", x => x.InStock.Match(true))
  .FilterFacet("In stock on sale", 
    x => x.InStock.Match(true) & x.OnSale.Match(true))

int inStock = result.FilterFacet("In stock").Count;

int inStockAndOnSale = result
  .FilterFacet("In stock on sale").Count;
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 31, 2016

Recommended reading