Facets are always empty
# help-with-umbraco
b
I am currently implementing the facetting in Examine 4.0.0-beta1. I'm using this function to get facet results for a specific field. I've checked and the field that I'm looking for does have a value.
Copy code
public static ICollection<LuceneFacetModel> GetFacetValues(this ISearchResults results, string field)
    {
        return results.GetFacet(field)
              .Select(f => new LuceneFacetModel
              {
                  Count = (int)f.Value,
                  Id = f.Label
              })
              .ToList();
    }
However I get an error that
Copy code
System.ArgumentNullException: 'Value cannot be null. Arg_ParamName_Name'
This is weird, since even when there are no facets you'd just want to return an empty list. I have registered the facet that I'm looking for by using this in my ConfigureNamedOptions implementation.
Copy code
var facetsConfig = new FacetsConfig();

        facetsConfig.DimConfigs.Add(Defaults.ParkFields.RelatedFacilities, new FacetsConfig.DimConfig { IsMultiValued = true });

        // set facetFullText fields
        // Note: https://shazwazza.github.io/Examine/articles/configuration.html contains all facetable fields.
        options.FieldDefinitions.AddOrUpdate(new FieldDefinition(Defaults.ParkFields.RelatedFacilities, FieldDefinitionTypes.FacetFullText));

        options.FacetsConfig = facetsConfig;
Does anyone know why this code, while searching for the field Defaults.ParkFields.RelatedFacilities would throw this exception?
It only seems to happen when the facetted field is not present in the index. This could probably be fixed by setting a default but it is still weird behaviour. When the facet isn't found it should just return empty and not throw an error. Is anyone familiair with this?
19 Views