I've got a hierarchy of pages such as
- Root
- Category 1
- Page 1
- Page 2
- Category 2
- Page 3
I want to use Find to create a filter based on the Category page names. Here's what I've got so far, the bit I can't figure out is line 4
var result = _searchClient.Search()
.For(query)
.Filter(x => x.Ancestors().Match(rootPageLink.ID.ToString()))
.FilterFacet("Categories", x => x.ParentLink) // This doesn't work
.HistogramFacetFor(x => x.Price, 100)
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.GetContentResult();
Obviously this doesn't work because Filter() expects a Filter as the second argument but you can see what I'm trying to do. It's roughly analagous to a SQL query like GROUP BY ParentLink
and then display info like
Category 1 (2 pages)
Category 2 (1 page)
Considering
The ISearchContent interface of UnifiedSearch contains two useful properties in your scenario
Consider you have a path like this
/returns/misc/yourstuff
When looking at Your Stuff as a unified search hit the SearchSection would be Returns and the SearchSubsection would be Misc
When looking at Misc hit the SearchSection would be Returns and the SearchSubsection would be
null
or not exist on the hit.This means
In your scenario the category pages would always be represented as SearchSections.
I'm unable to test this at the moment but something like this should get your started.
== Edit below==
To customize the SearchSection using projections something similar to this should be implemented, assuming you want the SearchSection to always be the closest parent of type
CategoryPage
.To implement in your Find Initialization
SearchSection extension method
Or something like that, you'll figure it out :)