Try our conversational search powered by Generative AI!

Filter By Site Id in Unified Search

Vote:
 

I've got a multi site set up and I want to be able to filter by site id but this is not available for me in unified search?

What's the best approach for this?

Martin

#194002
Jun 11, 2018 12:06
Vote:
 

You could try using SearchHitUrl to determine if the page is coming from the correct site.  Not sure if there is a more efficient way of doing it?

#194003
Jun 11, 2018 12:11
Vote:
 

Hi, if you are using Episerver Find there is a filter method you can use 'FilterOnCurrentSite'.

If you are not using Episerver Find then possibly use 'FilterForVisitor' this will filter on the current language, access rights, exclude container pages, exclude content folders and filter on current site.

#194004
Edited, Jun 11, 2018 12:29
Vote:
 

Hi Paul,

This didn't work as the search is unified search and FilterOnCurrentSite will only return IContentData.

#194005
Jun 11, 2018 12:37
Vote:
 

Hi Martin,

So you are using Episerver Find, did you try using 'FilterForVisitor'?

https://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/9/Integration/EPiServer-75/Filters/

Something like this might be what you are looking for:

ITypeSearch<ISearchContent> query = _client.UnifiedSearchFor(searchText);

var TypeFilter = _client.BuildFilter<PageData>().FilterForVisitor();

query = query.Filter(TypeFilter);

var results = query.GetResult();

return results;

You might be able to implement your own custom filter:

https://world.episerver.com/documentation/developer-guides/find/NET-Client-API/searching/Filtering/Custom-filtering-methods/

Thanks

[Pasting files is not allowed]

#194008
Edited, Jun 11, 2018 12:47
Vote:
 

Hi Paul,

Thanks this got us to what we wanted.

Instead of the FilterForVisitor extension method we used FilterOnCurrentSite.

var siteFilter = _searchClient.BuildFilter<PageData>().FilterOnCurrentSite();

var query = querySearch
                .UsingAutoBoost(TimeSpan.FromDays(DefaultDays))
                .TermsFacetFor(x => x.SearchSection)
                .FilterFacet(AllSections, x => x.SearchSection.Exists())
                .Filter(siteFilter);

Thanks

#194012
Jun 11, 2018 13:49
Vote:
 

Hi Martin,

Glad you got it sorted.

Paul

#194013
Jun 11, 2018 13:53
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.