Try our conversational search powered by Generative AI!

How to use AlwaysFilter in UnifiedSearch?

Vote:
 

Hi,


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
Vote:
 

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
Vote:
 

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

ForInstancesOf doesn't exist.

 

#64212
Dec 13, 2012 9:19
Vote:
 

Hmm, it does given that you're using the latest build (1.0.0.278). 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
Vote:
 

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 =>
        ((SubStartPage)filter).ExcludePageInSearch.Match(false)));

    

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