Episerver Search filter using parent page of Page reference type using UnifiedSearchFor

701 Views Asked by At

I have to implement search criteria in episerver. The existing search criteria includes pagetype filter which provides me the search result for the pagetype irrespective of where they are. I need to include another criteria of a parent page which is of type pagereference which basically will filter the pages and return records only which are part of the parent page. kindly advice.

1

There are 1 best solutions below

0
On BEST ANSWER

Well first if you have the parent page they why not use the ContentLoader instead of a search? Like this:

var loader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentLoader>(); 
var children = loader.GetChildren<%pageTypeHere%>(%parent pagereference%);

But if you wish to go with the search option:

query = query.Filter(x => x.Ancestors().Match(%parent pagereference id (so a int)%));