Try our conversational search powered by Generative AI!

Faceting on Categories -> get categories with 0 count



I'm faceting on EpiServer categories on a unified search. This is my query;

    var currentLangauge = Language.GetSupportedLanguage(ContentLanguage.PreferredCulture);
    ITypeSearch<ISearchContent> query = _epiFindClient.UnifiedSearchFor(string.Empty, currentLangauge);

    query = query.Filter(x => x.MatchType(typeof(T)));
    query = query.TermsFacetFor(x => x.SearchCategories, r => r.AllTerms = true);

    var result = query.Take(0).GetResult();

But it only gives me categories where the count isn't 0, I need those which are 0 as well. Is this possible?

Feb 03, 2014 15:12

And to get the categories:

    var categories = result.TermsFacetFor(x => x.SearchCategories).Terms;

Feb 03, 2014 15:14

Do any of your pages use the categories? If none of the pages in your site has the category set, I don't think they will show. As a test you could add a page that has all the categories checked.

Feb 04, 2014 17:13

Yes, I have pages with categories, and pages without.

Feb 05, 2014 9:23
Feb 05, 2014 9:23

But for the categories where you expect to get 0 hits, are there pages added in the site with those categories checked? If not, then the index will not know that these categories exists.
If there are pages with all categories, then r => r.AllTerms = true should have made this work.

Edited, Feb 05, 2014 9:47

So, in order to get 0 hits, at least 1 page has to be "tagged" with an category?

Feb 05, 2014 13:24

I think so, yes. As I mentioned earlier, you could verify by creating at least one page that has all categories checked.
If you need to show empty categories even without having any pages using them, I suppose you could load the category list and merge it with the facets. 

Feb 05, 2014 14:02

Per Magne, How to merge category list with facets ? can you give an example. I do have the same problem

Jun 16, 2014 16:58
* 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.