Vulnerability in EPiServer.Forms
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?
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.
Thanks Henrick - that makes sense.
How do I make sure that categories for files in the VPP are held in the SearchCategories property?
Create an extension named 'SearchCategories' (important as it is matched by name) returning a list of strings and register it as index:
SearchClient.Conventions.ForInstancesOf<UnifiedFile>().IncludeField(x => x.SearchCategories())