Faceting a Tags property

Hi all,

Been trying to follow blog posts and old discord threads to get Faceting working with no luck :frowning: I am using 16.1.1

ArgumentException: field "$facets" was not indexed with SortedSetDocValues

I have the following code

appsettings:

 "Examine": {
   "LuceneDirectoryFactory": "TempFileSystemDirectoryFactory"
 },

Composer :

builder.Services.ConfigureOptions<ConfigureExternalIndexOptions>();

ConfigureExternalIndexOptions:

internal class ConfigureExternalIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
    private static readonly string[] factedFields = [Constants.Search.ArticleTagsFieldName, Constants.Search.ArticleCategoriesFieldName];
  
    public void Configure(string? name, LuceneDirectoryIndexOptions options)
    {
        if (name?.Equals(UmbConstants.UmbracoIndexes.ExternalIndexName) == false)
        {
            return;
        }

        options.FieldDefinitions.AddOrUpdate(new FieldDefinition(nameof(ArticlePage.PublishedDate), FieldDefinitionTypes.DateTime));

       var facetsConfig = new FacetsConfig();

        foreach (var field in factedFields)
        {

            facetsConfig.SetMultiValued(field, true);
            options.FieldDefinitions.AddOrUpdate(new FieldDefinition(field, FieldDefinitionTypes.FacetFullText));
        }

        options.FacetsConfig = facetsConfig;
        options.UseTaxonomyIndex = true;
    }
}

SearchService (Cut down there is some optional filtering on the same facet fields)

var queryBuilder = index
        .Searcher
        .CreateQuery("content")
        .NodeTypeAlias(ArticlePage.ModelTypeAlias)
        .And()
        .ParentId(listingPageId)
       .WithFacets(facets => facets
                .FacetString(Constants.Search.ArticleTagsFieldName)
                .FacetString(Constants.Search.ArticleCategoriesFieldName)
            );

Luke Index view (I have no idea what I am doing with this thing :smiley: )

Thanks
Matt

Did you see Callum Whyte’s 2025 codegarden video.. just in case that is more up to date than any docs?

1 Like

Yes I have seen it but in the middle of battling with it completely forgot! I’ll go check it out again

Thanks

Sadly although I can step through the code it doesnt seem to effect the index. I added Callum’s path code and can see in Luke its till comma seperated

internal class ConfigureExternalIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
    private static readonly string[] factedFields = [Constants.Search.ArticleTags, Constants.Search.ArticleCategories];
    private readonly ILoggerFactory _loggerFactory;

    public ConfigureExternalIndexOptions(ILoggerFactory loggerFactory) => _loggerFactory = loggerFactory;

    public void Configure(string? name, LuceneDirectoryIndexOptions options)
    {
        if (name?.Equals(UmbConstants.UmbracoIndexes.ExternalIndexName) == false)
        {
            return;
        }
        options.IndexValueTypesFactory = new Dictionary<string, IFieldValueTypeFactory>
            {                
                { "list", new DelegateFieldValueTypeFactory(fieldName => new ListValueType(fieldName, _loggerFactory)) },
            };

        options.FieldDefinitions.AddOrUpdate(new FieldDefinition(Constants.Search.ArticlePublishedDate, FieldDefinitionTypes.DateTime));
        options.FieldDefinitions.AddOrUpdate(new FieldDefinition("path", "list"));
       
        foreach (var field in factedFields)
        {
            options.FacetsConfig.SetMultiValued(field, true);
            options.FieldDefinitions.AddOrUpdate(new FieldDefinition(field, FieldDefinitionTypes.FacetFullText));
        }
    }

    public void Configure(LuceneDirectoryIndexOptions options) => Configure(string.Empty, options);
}

Have you added the required ListValueType?

Yes, although I don’t think tags requires using it as the JSON is already tokenized properly as terms in the index.

:thinking: not doubting you as could have changed in v16… but

`{ “json”, new DelegateFieldValueTypeFactory(fieldName => new JsonValueType(fieldName, _loggerFactory)) },`

umbraco-search-extensions/src/Our.Umbraco.Extensions.Search/Composing/ConfigureIndexOptions.cs at dev · callumbwhyte/umbraco-search-extensions

I found the issue for some reason my ConfigureOptions is gettng called before Umbraco, which overrrides everything. So I have move it to a PostConfigure call and it is now working.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.