Try our conversational search powered by Generative AI!

EPiServer Find Search root filter



Is there an easy way to implement a search root filter with EPiServer Find? 

I.e if the search root is set, I only want search results from children of that page. Much the same that existed in the old search really.

I have been looking at the PagePath property, but that does not seem to be indexed by default. 

Does it exist anything out of the box, or have anyone built something like this? Seems to me that this is a basic requirement, so hopefully something already exists and I'm just unable to find it. 

EPiServer Version: CMS 6 R2


Sep 02, 2013 10:13

There is an extensions method for IContent called Ancestors, which I also believe gets automatically index. I suppose you could use that.
Something like this:

SearchClient.Instance.Search<SomePageType>().Filter(x => x.Ancestors().Match("1"))



Sep 05, 2013 9:20

Ah, you are using cms 6. Then that won't do you much good  :-\ 

Sep 05, 2013 9:22

It should not be too much code though:

        public static IEnumerable<int> GetParentIDs(this PageData page)
           // get parent ids here



and then

SearchClient.Instance.Conventions.ForInstancesOf<PageData>().IncludeField(x => x.GetParentIDs());


Edited, Sep 05, 2013 9:30

I resolved it using the following property in my basepage:

public IEnumerable<string> PagePathArray
return _dataFactory.GetParents(PageLink).ToString().Split('.');


Then the filter itself looks like this:

public ITypeSearch<IBasePageData> SearchRootFilter(ITypeSearch<IBasePageData> searchQuery, int searchRootId)
if (searchRootId > 0)
return searchQuery.Filter(x => x.PagePathArray.Match(searchRootId.ToString()));
return searchQuery;
//To use more than one searchRoot, use an .OrFilter();

Sep 05, 2013 16:06
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.