Facets doesn't exist in new Search abstraction

I am trying to set up faceting with the new search abstraction.

I did pretty much the same as in the demo site:

In a composer:

builder.Services.Configure<SearcherOptions>(options => options.ExpandFacetValues = true);
builder.Services.Configure<FieldOptions>(options =>
    options.Fields =
    [
        new()
        {
            PropertyName = ContentModels.ArticlePage.ModelPropertyAliases.Themes,
            FieldValues = FieldValues.Keywords,
            Facetable = true,
            Sortable = true
        },
        new()
        {
            PropertyName = ContentModels.ArticlePage.ModelPropertyAliases.PublicationDate,
            FieldValues = FieldValues.DateTimeOffsets,
            Sortable = true
        },
        new()
        {
            PropertyName = ContentModels.ArticlePage.ModelPropertyAliases.Headline, 
            FieldValues = FieldValues.Texts, 
            Sortable = true
        }
    ]
);

My search:

var results = await searcher.SearchAsync(
    indexAlias: Umbraco.Cms.Search.Core.Constants.IndexAliases.PublishedContent,
    query,
    filters: GetFilters(themes),
    facets: GetFacets(),
    sorters: GetSorters(orderBy),
    culture: culture,
    segment: segment,
    skip: skip,
    take: take
);

GetFacets is

var facets = new Facet[] { new KeywordFacet(ContentModels.ArticlePage.ModelPropertyAliases.Themes) };
return facets;

But all I get is

ArgumentException: field “$facets” was not indexed with SortedSetDocValues

Lucene.Net.Facet.SortedSet.DefaultSortedSetDocValuesReaderState..ctor(IndexReader reader, string field)

ConfigurationException: Tried querying a facet that did not exist, please configure your facets with FieldOptions.

Umbraco.Cms.Search.Provider.Examine.Services.Searcher.Search(IBooleanOperation searchQuery, IEnumerable filters, IEnumerable facets, IEnumerable sorters, int skip, int take)

I put a breakpoint in my composer to verify that the FieldOptions configuration is actually hit. I also rebuild all the indexes after configuring the fields.

Themes is a tag property, which should index Keywords by default.

You need to make sure your composer runs after the Examine one docs PR for it is below

It’s not isolated to the new abstraction either

That, and actually adding values to the fields fixed it :slight_smile: