question

VenkateshYellaboyina-0293 avatar image
0 Votes"
VenkateshYellaboyina-0293 asked MichaelHan-MSFT answered

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

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





office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered

Hi @VenkateshYellaboyina-0293,

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.