I'm making an app which lists all hub sites on an SP tenant. I want a user to click on a hub site and it shows all associated sites. Simple huh? No. I cannot figure out how to use sp.search
The documentation is notoriously assumptive. Here is what I've attempted:
export const GetAssociatedSites = async (hubId: string | undefined) => {
const _sp = getSP();
const finalArray: any[] = [];
await _sp.search({
StartRow: 0,
QueryTemplate: "contentclass: STS_Site AND DepartmentId:1111*",
Querytext: 'contentclass:STS_Site contentclass:STS_Web',
//SiteTitle:{searchTerms} AND contentclass:STS_site AND DepartmentID:{{PageContext.hubSiteId}}
SelectProperties: [
"Title",
"SPSiteUrl",
"WebTemplate",
"SPWebUrl",
"SiteName",
"RelatedHubsites",
"IsHubSite",
"ParentLink",
"Department",
"Path"
],
RefinementFilters: [`departmentid:string("${hubId}",linguistics=off)`],
RowLimit: 500,
TrimDuplicates: false,
})
.then((r: SearchResults) => {
r.PrimarySearchResults.forEach((value) => {
finalArray.push(value)
});
currentResults = r
})
console.log(currentResults, 'currentResults')
return currentResults;
}
I get no results back. Any help with this?