Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Unified search - using category filters and facets


I am trying to understand how to implement filters and facets for categories with a unified search.

I have tried specifying and accessing the ISearchContent.SearchCategories propeties like this:

var query = SearchClient.Instance.UnifiedSearchFor('query');

// Add facets
query.TermsFacetFor(x => x.SearchCategories);

// Get results
var results = query.GetResult();

// Get category facets for results
var facets = results.TermsFacetFor(x=> x.SearchCategories);

When I try to get the facets into variable 'facets', a null reference exeption is thorwn.

I kind of expect this as I don't understand how Finds will know how to collate categories across the pages, blocks and files from the unified search.

Is it possible to-do this with a unified search? Are there any examples?






Jun 14, 2013 11:53

You have to chain 'query':

query = query.TermsFacetFor(x => x.SearchCategories)

as it won't be added to the current object and therefore it is not requested when you execute the query.

Edited, Jun 14, 2013 13:03

Thanks Henrick - that makes sense.


How do I make sure that categories for files in the VPP are held in the SearchCategories property? 


Jun 14, 2013 16:33

Create an extension named 'SearchCategories' (important as it is matched by name) returning a list of strings and register it as index:

.IncludeField(x => x.SearchCategories())

Jun 14, 2013 16:49
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.