2

Using either Search Query tool or modern search WebParts (SPFx), is it possible to filter results from a specific hub site or site in a hub site ?

In the search query tool view all properties dialog, I don't see any managed property that suggest this is possible.

2 Answers 2

2

Ok, quite simply actually.

Thanks to this issue, I found that the DepartmentId corresponds to the hub site.

So, this KQL filters on the hub site :

DepartmentId:"{24af7e54-d2f9-422d-a44e-6a6d40077d50}"

or (no more working)

DepartmentId:"{Site.ID}"

or (credits to @Alberto)

DepartmentId:{{PageContext.hubSiteId}}

if from a web-part.

7
  • I am trying to use the current site ID in my search query, but it doesnt work... any idea/suggestion? DepartmentId:{{Site.ID}} {searchTerms}
    – Alberto S.
    Jan 2, 2020 at 16:02
  • 1
    You have double {{ and }} .... is it a typo ?
    – Steve B
    Jan 7, 2020 at 13:28
  • I tried with double {{ and single {, but never got it to work. Can you confirm that if I run such KQL sentence, it will perform the search filtering results by DepartmentId={current site ID} ( in order to perform searches from the central hubsite itself ). thanks
    – Alberto S.
    Jan 7, 2020 at 13:59
  • I use this syntax without issue. Can you describe what happens ? No result ? erro r?
    – Steve B
    Jan 7, 2020 at 14:00
  • 1
    I confirm u that another workaround is to just use DepartmentId:{{PageContext.hubSiteId}}, it works as well :)
    – Alberto S.
    Jan 8, 2020 at 10:23
0

Tip. If you're using PnP Modern Search Solution V4, you need to escape the curly braces.

You can escape curly braces characters using '' to avoid: ex: DepartmentId:{edbfd618-ef1d-4cc5-a214-95bf44ddf4ee}

https://microsoft-search.github.io/pnp-modern-search/usage/search-results/tokens/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.