How to use AlwaysFilter in UnifiedSearch?

Member since: 2007


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) ... );


#64193 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))

    #64206 Edited, Dec 13, 2012 0:50
  • Member since: 2007

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

    ForInstancesOf doesn't exist.


    #64212 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.

    #64239 Dec 14, 2012 0:11
  • Member since: 2007

    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 =>


    #64252 Dec 14, 2012 13:56