Try our conversational search powered by Generative AI!

filter search and search results based on url


I have a site called in this site i have 2 minimal subsites in it (A and B).

search page exists in parent site that is only.

when i click any link inside A or B site then my URL is or

after navigating to A site when i search , search results should display within A or B only.

if my URL in browser or site and if am searching then serach results should be display from or only not inlcude all.

Edited, Aug 14, 2020 7:13


If I understand the issue correctly, you're looking for a way to limit the results you're returning from a search to only include content from within a section of the site (in your example, either A or B depending on the site the user is currently viewing). I think the way I'd approach that would be to filter using Ancestors() to limit results to those with an ancestor of the required section. Something like this:

ContentReference ancestorContentRef;
if (currentSubsite == siteA)
    ancestorContentRef = contentRefOfSiteA;
    ancestorContentRef = contentRefOfSiteB;
var query = SearchClient.Instance.Search<MyContentType>()
    .Filter(x => x.Ancestors().Match(ancestorContentRef.ToString()));
Aug 14, 2020 8:33
* 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.