Try our conversational search powered by Generative AI!

Epi-Find: TermsFacet for counts inaccurate when corresponding filter is applied


I have the following facet on my Epi Find query.

public void ApplyManufacturerFacet()
    this.EpiFindSearch = this.EpiFindSearch.TermsFacetFor(r => r.ManufacturerId);

I am using the facet terms to retrieve counts for various filters that could be applied. I apply the filter with the following:

public void SearchByManufacturer(List manufacturers)
    var catalogBuilder = this.EpiFindSearch.Client.BuildFilter();
    foreach (var manufacturer in manufacturers)
        catalogBuilder = catalogBuilder.And(r => r.ManufacturerId.Match(manufacturer));
    this.EpiFindSearch = this.EpiFindSearch.Filter(catalogBuilder);

When certain filters are applied, the number of results that are actually returned does not match the number that was returned by my request for the facet count. Here is the calling code for these functions. You can see that the filter is applied first, then the request for the facets is made.

if (manufacturers.Count > 0)

Can anybody tell me why these filter counts aren't correct?  

Edited, Aug 24, 2017 15:47

Shouldn't you build an Or-filter or do you want to match results on all?

Aug 29, 2017 21:25

Hi Johan, I believe I have these set up correctly.  Regardless, I tried with an Or-filter and the problem remains, the count advertised vs. actual is still not correct.

Aug 29, 2017 21:57

Which properties are you looking at when rendering? I also think the order might matter. Have you tried calling Filter() after TermsFacetFor()?

Aug 29, 2017 22:19

I swapped the calls but it hasn't seemed to have made a difference.  I'm still seeing the inaccurate counts.

I'm not sure what you mean by what properties I'm looking at while rendering.  Here is how I'm getting the data about facets back out of the search to pass to the client, if that's helpful:

                public Dictionary<string, int> GetManufacturerCounts(IContentResult<SiteProductVariation> results)
			Dictionary<string, int> facetResults = new Dictionary<string, int>();
			var facetItems = results.TermsFacetFor(r => r.ManufacturerId);
			foreach (var item in facetItems)
				facetResults.Add(item.Term.Replace('-', ' '), item.Count);
			return facetResults;

After this runs the resulting dictionary is just put in an object with the name of the filter and a set of list items which is all passed to the client as an object to render:

		public Facet GetManufacturerFacet(IContentResult<SiteProductVariation> dataList)
			var manufacturerFilter = search.GetManufacturerCounts(dataList);
			List<System.Web.UI.WebControls.ListItem> items = manufacturerFilter
				.Select(m => new System.Web.UI.WebControls.ListItem { Text = m.Key, Value = m.Key })
			Facet facet = new Facet()
				Title = "Manufacturer",
				Name = "ManufacturerId",
				Items = items,
				ApplicableResults = manufacturerFilter.Values.ToList()
			return facet;

Does this answer your questions?

Aug 29, 2017 23:50

Yes, item.Count is what I meant. What type of objects are you querying? Are they Epi Content, the problem might be in using FilterForVisitor() or not or GetContentResult() vs. GetResult().

You could also check the HTTP traffic using Fiddler and compare with the search view in Find UI for more clues.

Aug 30, 2017 7:51

Are you hitting the default facet size limit?


By default, only 10 facets will be returned. To increase this use:

.TermsFacetFor(x => x.Category, facet => facet.Size = 25)

Answer from:

Edited, Aug 30, 2017 15:55


I am querying a class that inherits from the Episerver Commerce VariationContent class.  If I follow that down it does inherit from ContentData.  I am using GetContentResult to execute the search, as you can see here:

		protected virtual IContentResult<T> ExecuteSearch(out int totalResults, double relevancyThreshold = 0, int displayStart = 0, int displayLength = 10)
			var search = EpiFindSearch.Skip(displayStart).Take(displayLength).FilterOnReadAccess().FilterForVisitor();
			var resultSet = search.Track().GetContentResult();
			totalResults = resultSet.TotalMatching;
			return resultSet;

I tried removing the filter on read and for visitor just to see if this had an effect based on your suggestion but it did not.  I have noticed that when the numbers are different the actual results have always been more than the expected.  I'm not sure if that's pointing to filtering as the issue.  I can look into Fiddler, but I'm not sure exactly what I should be looking for.


The question isn't really about the number of facets, but rather the facet counts that are returned when I filter on that facet.  Please see my post above.

Aug 30, 2017 17:28

As a part of an unrelated bug I was working on, I enlarged the facet size returned to 50, rather than the default of ten.  However, when I tested this, I noticed that the counts were now accurate on each of the facets.  I'm not sure how the number of facets returned is related to the count of results for each facet, so I'd be interested if someone could explain that, but I believe I have solved my original problem.  Thank you both for your help.

Aug 31, 2017 17:51

Another easy thing to try is to clear the index and also make sure that there aren't multiple consuming apps introducing "corruption" or unnecessary data in the index.

Sep 01, 2017 8:17
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.