How to perform search on SharePoint Hub Site and its associated site

Venkatesh Yellaboyina 21 Reputation points
2021-05-11T14:55:54.307+00:00

Dear All,

Request you to let us know how we can search for a specific text value(i.e.: Developer or Training) across SharePoint Hub Site and its associated sites using CSOM in c#.
can we use KeywordQuery and SearchExecutor for SharePoint Hub Site & its associated sites, will it work?

Please provide references or sample code snippet using CSOM.

Thanks & Regards,
Venkatesh Yellaboyina

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,126 Reputation points
    2021-05-12T03:06:49.193+00:00

    Hi @Venkatesh Yellaboyina ,

    At the heart of hub sites in regards to search is the managed property named DepartmentId which is the site id of the hub site. Both the hub site and sites associated to the hub site have the same id in this property. Here is a good article about search across hub site: https://www.sharepointnutsandbolts.com/2019/10/search-sharepoint-hub-sites.html

    So you could add DepartmentId:{hub-site-id} in queryText to seach across SharePoint Hub Site. Below is my example for you:

            KeywordQuery keywordQuery = new KeywordQuery(ctx);  
            keywordQuery.QueryText = "Developer AND DepartmentId:{feed558d-83e7-445b-81f1-8b4b3d14f146}";  
            SearchExecutor searchExecutor = new SearchExecutor(ctx);  
            ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);  
            ctx.ExecuteQuery();  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.