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) ... );
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))
Maybe I should clarify that this is for EPiServer 6 R2.
ForInstancesOf doesn't exist.
Hmm, it does given that you're using the latest build (220.127.116.118). 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.
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.