Closed cardinalpipkin closed 3 months ago
Hi. It looks like you may have too many curly braces for your bracketId.
you've added {} around $hubId
const bracketHubId =
{${hubId}};
and now you're adding another set of {} around it.
const url = "https://blah blah/_api/search/query?querytext='DepartmentId:{" + bracketHubId + "}
Which would result in
https://blah blah/_api/search/query?querytext='DepartmentId:{{bracketHubId}}'
which isn't valid.
Thank you so much for your reply, it now seems to work, but I'm getting some associated sites from some hubId's but not others. Some of the hubs definetly do have associated sites. Is there something wrong with the query?
await _sp.search({
StartRow: 0,
Querytext: '(contentclass:"STS_Site") (contentclass:"STS_Web")',
QueryTemplate: `contentclass: STS_site AND DepartmentId:${bracketHubId}`,
SelectProperties: [
"Title",
"SPSiteUrl",
"WebTemplate",
"WebId",
"SPWebUrl",
"SiteName",
"RelatedHubsites",
"IsHubSite",
"ParentLink",
"Department",
"DepartmentId",
"Path"
],
Here is the receiving function if it's any use:
const getAssociatedSitesRest = (hubSite: string) => {
GetChildSites(hubSite).then((associatedSites: SearchResults) => {
console.log(associatedSites, 'associatedSites results')
setAssociatedSitesRest(associatedSites.PrimarySearchResults)
});
};
It looks right to me. We're just a passthrough to the search API so it may be something from Microsoft's end causing the issue. There has been a service notice in the admin center that Search has had indexing issues since January. Maybe this could be part of the problem?
I'm hoping it is and it's not my query.
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.
What version of PnPjs library you are using
3.x
Minor Version Number
18.0
Target environment
SharePoint Framework
Additional environment details
All webparts are allowed on tenant. Visual Studio Code. SharePoint Online. Creating WebParts and Extensions.
Question/Request
I'm struggling to get any results when using sp.search. I am passing sp.search a hub Id, I want search to then find all the associated sites for that hub Id. I just don't know what the query should be. I've read the documentation thoroughly. This is what I'm using:
I've left all my attempts in as commented out code. I'm fairly sure my query text is not correct.