SaaS CMS has officially launched! Learn more now.

Episerver Find: Get search results from page and subpages


I'm creating a search function that should return page specific search results.

I.e. if I have a News page I would like to search only in that page and its children Article pages.

Does a filter for such function exist in the Episerver Find API? 

Jun 28, 2019 14:24

You can pass page types to filter, into your search query as shown below

var contentTypeIds = new List<int>
var searchQuery = this._findClient;
var contentTypeFilter = this._findClient.BuildFilter<IContent>();
if (contentTypeIds != null && contentTypeIds.Any())
    foreach (var contentTypeId in contentTypeIds)
        contentTypeFilter = contentTypeFilter.Or(x => x.ContentTypeID.Match(contentTypeId));

searchQuery = searchQuery.Filter(contentTypeFilter);

var results = searchQuery.GetContentResult();

Let me know if you need more information.

Edited, Jun 28, 2019 14:50

You can also filter to get only below a specific content (like your news listing)

.Filter(x => x.Ancestors().Match(newsListingPage.ContentLink.ToReferenceWithoutVersion().ToString())
Jun 28, 2019 15:12


If I read your post correctly, you're looking to return a set of results filtered to be only descendents of a given page (e.g. news page). To do this you can filter on Ancestors() which contains a string array of the IDs of all of the ancestors of a given page as follows:

var parentId = parentPage.ContentLink.ID.ToString();
var results = searchClient.Search<ArticlePage>().Filter(x => x.Ancestors().Match(parentId)).GetContentResult();
Jun 28, 2019 15:18

Thank you for your answers. I will try them out and see which suggestion matches my requirements!

Jun 28, 2019 15:20
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.