London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Disable .FilterOnCurrentSite() for UnifiedSearch

Vote:
 

Is there a way to disable the default filtering .FilterOnCurrentSite() for UnifiedSearch?

I'm building a search feature where it will be optional to filter by site.

This post describes a way of doing it but I wonder if there's a way to just disable that specific filter without have to redefine the rest?

https://world.episerver.com/forum/developer-forum/EPiServer-Search/Thread-Container/2015/6/unifiedsearch-with-multiple-sites/

#199407
Nov 26, 2018 14:24
Vote:
 

Ended up copying some decompiled Episerver code and disabling  .FilterOnCurrentSite() in the .PublicSearchFilter()

This should be placed in an InitializableModule.

// Code from CmsUnifiedSearchSetUp.cs in Episerver.Find.Cms DLL 13.0.5
var cmsUnifiedSearchSetup = new EPiServer.Find.Cms.CmsUnifiedSearchSetUp();

SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<PageData>()
    .PublicSearchFilter((Func<IClient, ISearchContext, Filter>)((c, ctx) => (Filter)c.BuildFilter<IContentData>()
        .FilterForVisitor<IContentData>(this.GetLanguage(ctx)
        ).ExcludeContainerPages<IContentData>()
        .ExcludeContentFolders<IContentData>()
        //.FilterOnCurrentSite<IContentData>()
        ))
    .CustomizeIndexProjection(new Func<IndexProjectionBuilder, IndexProjectionBuilder>(cmsUnifiedSearchSetup.CustomizeIndexProjectionForPageData))
    .CustomizeProjection(new Func<HitProjectionBuilder, HitProjectionBuilder>(cmsUnifiedSearchSetup.CustomizeProjectionForPageData));

SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<MediaData>()
    .PublicSearchFilter((Func<IClient, ISearchContext, Filter>)((c, ctx) => (Filter)c.BuildFilter<IContentData>()
        .FilterForVisitor<IContentData>(this.GetLanguage(ctx))
        .ExcludeContentFolders<IContentData>()
        //.FilterOnCurrentSite<IContentData>()
        ))
    .CustomizeIndexProjection(new Func<IndexProjectionBuilder, IndexProjectionBuilder>(cmsUnifiedSearchSetup.CustomizeIndexProjectionForMediaData))
    .CustomizeProjection(new Func<HitProjectionBuilder, HitProjectionBuilder>(cmsUnifiedSearchSetup.CustomizeProjectionForMediaData));

// Code from CmsUnifiedSearchSetUp.cs in Episerver.Find.Cms DLL 13.0.5
private string GetLanguage(ISearchContext context)
{
    if (context.Payload.ContainsKey("Culture") && context.Payload["Culture"].IsNotNull())
        return ((CultureInfo)context.Payload["Culture"]).Name;
    if (context.ContentLanguage == null || context.ContentLanguage == Language.None)
        return Languages.AllLanguagesSuffix;
    return context.ContentLanguage.FieldSuffix;
}

#200539
Jan 15, 2019 11:23
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.