How to use AlwaysFilter in UnifiedSearch?



I'm trying to use AlwaysFilter, but not sure how to. This is what I'm trying to achieve:


SearchClient.Instance.Conventions.UnifiedSearchRegistry.AlwaysFilter(typeof(RegularPage), f => ((RegularPage)f).ExcludePageInSearch.Match(false));

But I always get "Unable to cast object of type 'EPiServer.Find.Client' to type...". I also tried with:


SearchClient.Instance.Conventions.UnifiedSearchRegistry.AlwaysFilter(typeof(RegularPage), f => f.MatchTypeHierarchy(typeof(RegularPage) ... );


Dec 12, 2012 16:43

I can look up the exact syntax when I'm on a suitable computer later, but I think what you want to do is go something like

UnifiedSearchRegistry.ForInstancesOf<PageData>().AlwaysFilter(f => f.MatchTypeHierarchy(typeof(RegularPage))

Edited, Dec 13, 2012 0:50

Maybe I should clarify that this is for EPiServer 6 R2.

ForInstancesOf doesn't exist.


Dec 13, 2012 9:19

Hmm, it does given that you're using the latest build ( It's an extension method though so you'll need a using statement for EPiServer.Find.UnifiedSearch.

Also, correction to my previous post, what you probably want to do is something like:

UnifiedSearchRegistry.ForInstancesOf<PageData>().AlwaysFilter(client => CreatePageFilter(client));
The CreatePageFilter method should be a static method in which you can create a filter using client.BuildFilter<PageData>() and then return it.

Dec 14, 2012 0:11

Thanks, worked alot better when using that namespace.

But it was a little bit cumbersome, we have a common base class with the property, but we don't want to include all types inheriting from that class. So ended up with a filter for each type that we include in the unified search.


SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<SubStartPage>().AlwaysApplyFilter(client =>
    client.BuildFilter<SubStartPage>().And(filter =>


Dec 14, 2012 13:56
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.