Ignore descendants from pages with bool property "HideInSearch" = true

Vote:
 

Hello,

I am new to Episerver Find, which I am implementing instead of SiteSeeker, for a customer.

The customer want to be able to choose some pages (with descendants) to not show in the search result. These pages could be of any page type or at any place in the hierarchy.
We are using a base page type that inherits from PageData, and all other page types inherit from that base page type. We will call this property "HideInSearch".

Is there a simple way to use this in a filter?

As I am new to Episerver Find I'm not totally sure how to do this.
I was thinking of to first do a search for all pages "HideInSearch" set to true, to get a list of id for these pages, then a filter like this:

.Filter(x => !x.MatchTypeHierarcy(typeof(BasePageType)) | !((BasePageType)x).Ancestors().In(idList))


But I'm not sure this is the best way?

Best Regards
Niklas

#205263
Jul 03, 2019 15:32
Vote:
 

Hi Niklas, 

So the ancestors of IContent are indexed in Find, so you can do something like:

.Filter(x => x.Ancestors().Match("configuredPageId"))

This will match on one configured link to a page - if you're setting up multiple page links, you could just iterate over them and chain the filter with Or filters.
Have a lok at the use of Filter Builders here (bottom of the page):
https://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/9/DotNET-Client-API/Searching/Filtering/Filtering/

Thanks,
Paul

#205266
Edited, Jul 03, 2019 16:20
Vote:
 

Hi Paul,

Thank you, that worked splendidly!

Best Regards
Niklas

#205284
Jul 04, 2019 9:59
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.