0

I have added to the HelloWorld web part starting example to include a search, and I have successfully limited it to my site instead of the entire tenant.

const here = this.context.pageContext.web.absoluteUrl;
this.context.spHttpClient.get(`${here}/_api/search/query?querytext='${toSearchFor} IsDocument:true Site:${here}'
    &expand=Files/ListItemAllFields
    &rowLimit=20`,
    SPHttpClient.configurations.v1,
      {
        headers: [
          ['accept', 'application/json;odata=verbose'],
          ['odata-version', '']
        ]
      })
     .then((res: SPHttpClientResponse): Promise<{}> => {
        return res.json();
     })

This works and only searches my site. Now I'm trying to limit it further by setting the path to a folder 'Documentation' inside of Shared Documents.

const searchTarget = "https://my.sharepoint.com/sites/name/Shared%20Documents/Documentaion";
this.context.spHttpClient.get(`${here}/_api/search/query?querytext='${toSearchFor} IsDocument:true Site:${searchTarget}'

also tried

searchTarget = "https://my.sharepoint.com/sites/name/Shared Documents/Documentaion";
searchTarget = "https://my.sharepoint.com/sites/name/Shared\ Documents/Documentaion";
searchTarget = "(https://my.sharepoint.com/sites/name/Shared Documents/Documentaion)";
searchTarget = "https://my.sharepoint.com/sites/name/Shared%20Documents/Documentaion";
searchTarget = "https://my.sharepoint.com/sites/name/Shared+Documents/Documentaion";

But anything other than 'this.context.pageContext.web.absoluteUrl' returns 0 results.

1 Answer 1

0

Try using the Path managed property instead, like:

const searchTarget = "https://my.sharepoint.com/sites/name/Shared%20Documents/Documentaion*";
this.context.spHttpClient.get(`${here}/_api/search/query?querytext='${toSearchFor} IsDocument:true path:${searchTarget}'

Note the asterix at the end of searchTarget to make it do prefix matching

1
  • this also got 0 results.
    – Mark
    Commented Jan 9, 2023 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.