
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.