solr express
Search…
Facet query

Feature

Create a facet query

How to

    1.
    Configure facet
1
DocumentCollection<TechProductDocument> documentCollection; // from DI
2
3
var rersult = documentCollection
4
.Select()
5
.FacetQuery("AliasName", q => q.Field(f => f.Features))
6
.Execute();
Copied!
    1.
    Optionally, change one or more settings
1
DocumentCollection<TechProductDocument> documentCollection; // from DI
2
3
var rersult = documentCollection
4
.Select()
5
.FacetQuery("AliasName", q => q.Field(f => f.Features), 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" or some alias (if configured)
7
var facetName = facetItem.Name;
8
//facetType = FacetType.Field
9
var facetType = facetItem.FacetType;
10
11
foreach (FacetItemQuery facetItem in data)
12
{
13
// facetName = "AliasName"
14
var facetName = facetItem.Name;
15
//facetType = FacetType.Query
16
var facetType = facetItem.FacetType;
17
// nested = nested facet (if configured)
18
var nested = facetItem.Facets;
19
// quantity = quantity of item's value
20
var quantity = facetItem.Quantity;
21
}
22
}
Copied!

Settings

Use case
How to
Sort type of result of facet
.FacetQuery("AliasName", q => q.Field(f => f.Features), facet => facet.SortType(FacetSortType.CountAsc))
Minimum count of itens in facet's result
.FacetQuery("AliasName", q => q.Field(f => f.Features), facet => facet.Minimum(2))
Limit of itens in facet's result
.FacetQuery("AliasName", q => q.Field(f => f.Features), facet => facet.Limit(10))
List of tags to exclude in facet calculation
.FacetQuery("AliasName", q => q.Field(f => f.Features), facet => facet.Excludes(new[] { "tag1", "tag2" }))
Specify a filter or list of filters to be intersected with the incoming domain before faceting
.FacetQuery("AliasName", q => q.Field(f => f.Features), facet => facet.Filter(f => f.Field(q => q.Id).EqualsTo(10)))

NOTE

Learn more about queries
Last modified 2yr ago
Copy link