Try our conversational search powered by Generative AI!

Unified Search - Excluding pages by property


I have a Boolean property on all the pages in my site called 'IncludeInSearch'.

I want to configure an 'AlwaysApplyFilter' on the UnifiedSearchRegistry to exclude pages from unified searches when IncludeInSearch=false.

As far as I am aware, I cannot see any IClient extensions to allow me to-do this.

I can see Henrick has created an example custom filter or fuzzy searches which I guess I could do, however I can see there already a Boolean custom filter at EPiServer.Find.Api.Querying.Filters.BoolFilter which I think I can use?

Im not sure how this all pieces together but essentially I want the end result to look like this in the find initialization:

                .AlwaysApplyFilter(c => c.BuildFilter<SitePageBase>().FilterExcludeFromSearch());

 Can anyone help?

Jun 14, 2013 17:17


You can do like this:

    .PublicSearchFilter(page => !page.MatchTypeHierarchy(typeof(SitePageBase)) | ((SitePageBase)page).IncludeInSearch.Match(true));

If you're indexing SitePageBase you can remove the MatchTypeHierarchy expression and use it as the type parameter instead. Often you don't want to index all of your page types inheriting from SitePageBase. So then it would be like:

    .PublicSearchFilter(page => page.IncludeInSearch.Match(true));




Jun 15, 2013 11:39

... and if you really want to use AlwaysApplyFilter:

    .AlwaysApplyFilter(c => c.BuildFilter<SitePageBase>()
        .And(page => page.IncludeInSearch.Match(true)));


Jun 15, 2013 11:42

Thanks Johan, 

I adapted the third example to work

                .AlwaysApplyFilter(c => c.BuildFilter<SitePageBase>()
                    .And(page => page.IncludeInSearch.Match(true)));


I had to include the Add<T> else the website was throwing an exception on startup with 'The type SitePageBase has not been added'.

I could not get the first two examples to work as in each instance I was getting an exception 'Cannot cast IClient to SitePageBase'. It seems in each, the page variable in the lambda expression is of type IClient.

Edited, Jun 16, 2013 10:02
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.