Try our conversational search powered by Generative AI!

Faceting on Categories -> get categories with 0 count

Vote:
 

Hi.

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?

#80837
Feb 03, 2014 15:12
Vote:
 

And to get the categories:

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

#80838
Feb 03, 2014 15:14
Vote:
 

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.

#80906
Feb 04, 2014 17:13
Vote:
 

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

#80924
Feb 05, 2014 9:23
Vote:
 
#80925
Feb 05, 2014 9:23
Vote:
 

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.

#80928
Edited, Feb 05, 2014 9:47
Vote:
 

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

#80940
Feb 05, 2014 13:24
Vote:
 

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. 

#80941
Feb 05, 2014 14:02
Dan
Vote:
 

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

#87528
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.