filter search and search results based on url

Vote:
 

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

search page exists in parent site that is abcd.com only.

when i click any link inside A or B site then my URL is abcd.com/A or abcd.com/B.

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

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

#226514
Edited, Aug 14, 2020 7:13
Vote:
 

Hi,

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;
}
else
{
    ancestorContentRef = contentRefOfSiteB;
}
var query = SearchClient.Instance.Search<MyContentType>()
    .Filter(x => x.Ancestors().Match(ancestorContentRef.ToString()));
#226516
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.