November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hi,
You can do like this:
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<PageData>()
.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:
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<SitePageBase>()
.PublicSearchFilter(page => page.IncludeInSearch.Match(true));
... and if you really want to use AlwaysApplyFilter:
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<SitePageBase>()
.AlwaysApplyFilter(c => c.BuildFilter<SitePageBase>()
.And(page => page.IncludeInSearch.Match(true)));
Thanks Johan,
I adapted the third example to work
SearchClient.Instance.Conventions.UnifiedSearchRegistry
.Add<SitePageBase>()
.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.
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:
Can anyone help?