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?
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?
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.
This didn't work as the search is unified search and FilterOnCurrentSite will only return IContentData.
So you are using Episerver Find, did you try using 'FilterForVisitor'?
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();
You might be able to implement your own custom filter:
[Pasting files is not allowed]
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
.TermsFacetFor(x => x.SearchSection)
.FilterFacet(AllSections, x => x.SearchSection.Exists())
Glad you got it sorted.