AI OnAI Off
You can pass page types to filter, into your search query as shown below
var contentTypeIds = new List<int>
{
this._contentTypeRepository.Load<StoryPage>().ID,
this._contentTypeRepository.Load<GeneralPage>().ID
};
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.
You can also filter to get only below a specific content (like your news listing)
.Filter(x => x.Ancestors().Match(newsListingPage.ContentLink.ToReferenceWithoutVersion().ToString())
Hi,
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();
Thank you for your answers. I will try them out and see which suggestion matches my requirements!
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?