Greg B
Greg B

Reputation: 14888

Do Facets respect Filters in Episerver Find?

I'm using the .NET Client to query Episerver Find, I'm filtering the results on an ancestor Page Id to search within sub-sections of the site and this works fine:

var result = _searchClient.Search<ProductPageData>()
                          .For(query)
                          .Filter(x => x.Ancestors().Match(sectionPageLink.ID.ToString()))
                          .GetContentResult();

Now I want to add some facet navigation so I'm using HistogramFacetFor and TermsFacetFor but the counts in the facet counts don't appear to be respecting the Filter operations:

var result = _searchClient.Search<ProductPageData>()
                          .For(query)
                          .HistogramFacetFor(x => x.Price, PriceInterval)
                          .TermsFacetFor(x => x.Brand)
                          .Filter(x => x.Ancestors().Match(rootPageLink.ID.ToString()))
                          .GetContentResult();

Results in the following numbers:

result.TotalMatching = 11

Brand:
    Brand 1 : 5 items
    Brand 2 : 6 items
    Brand 3 : 3 items
      Total = 14

Price:
      0 - 100 : 2
    101 - 200 : 5
    201 - 300 : 7
        Total = 14

Without the filter the TotalMatching is 14, so it appears Facets don't respect the Filter(), is this correct or am I doing something wrong?

Upvotes: 1

Views: 1100

Answers (1)

Johan Petersson
Johan Petersson

Reputation: 1027

Have you tried moving the Filter above the facets? Filters should affect facets, unless you're using FilterHits instead of just Filter.

Upvotes: 0

Related Questions