solr express
Search…
Facet field

Feature

Create a facet field

How to

    1.
    Configure facet
1
DocumentCollection<TechProductDocument> documentCollection; // from DI
2
3
var rersult = documentCollection
4
.Select()
5
.FacetField(q => q.InStock)
6
.Execute();
Copied!
    1.
    Optionally, change one or more settings
1
DocumentCollection<TechProductDocument> documentCollection; // from DI
2
3
var rersult = documentCollection
4
.Select()
5
.FacetField(q => q.InStock, facet =>
6
{
7
facet.Minimum = 3;
8
facet.Limit = 5;
9
})
10
.Execute();
Copied!
    1.
    Read data
1
rersult
2
.Facets(out var data);
3
4
foreach (FacetItemField facetItem in data)
5
{
6
// facetName = "InStock"
7
var facetName = facetItem.Name;
8
//facetType = FacetType.Field
9
var facetType = facetItem.FacetType;
10
11
foreach (var facetItemValue in facetItem.Values)
12
{
13
// nested = nested facet (if configured)
14
var nested = facetItemValue.Facets;
15
// key = value of item's value
16
var key = facetItemValue.Key;
17
// quantity = quantity of item's value
18
var quantity = facetItemValue.Quantity;
19
}
20
}
Copied!

Settings

Use case
How to
Sort type of result of facet
.FacetField(q => q.InStock, facet => facet.SortType(FacetSortType.CountAsc))
Minimum count of itens in facet's result
.FacetField(q => q.InStock, facet => facet.Minimum(2))
Limit of itens in facet's result
.FacetField(q => q.InStock, facet => facet.Limit(10))
List of tags to exclude in facet calculation
.FacetField(q => q.InStock, facet => facet.Excludes(new[] { "tag1", "tag2" }))
Specify a filter or list of filters to be intersected with the incoming domain before faceting
.FacetField(q => q.InStock, facet => facet => facet.Filter(f => f.Field(q => q.Popularity).EqualsTo(10)))
Method type to how to facet the field
.FacetField(q => q.InStock, facet => facet.MethodType(FacetSortType.UninvertedField))
Prefix to only produce buckets for terms starting with the specified value
.FacetField(q => q.Features, facet => facet.Prefix("some value"))

NOTE

Learn more about queries Learn more about facets
Last modified 2yr ago
Copy link