0

I'm trying to search Sharepoint & Teams files through POST https://graph.microsoft.com/v1.0/search/query. I passed the entityType as listItem in the request body so that I could able to search Sharepoint, Teams & Onedrive files.

But in my case, I should ignore the files from Onedrive.

Is there a way to filter OneDrive files & search only Sharepoint & Teams files?

  • Does this answer your question? [How to search sharepoint file across document library](https://stackoverflow.com/questions/69121276/how-to-search-sharepoint-file-across-document-library) – user2250152 Sep 13 '21 at 06:17
  • Nope. This is a bit different from the earlier question. Here I'm trying to restrict Onedrive files even I tried to filter using `contentclass:STS_ListItem_DocumentLibrary` but that doesn't work. – WSI Appfactory Sep 13 '21 at 11:08

1 Answers1

1

The url of OneDrive files starts with https://contoso-my.sharepoint.com/, and the url of SharePoint files starts with https://contoso.sharepoint.com/.

So you could add filter in th query like this to ignore Onedrive files:

path:\"https://contoso.sharepoint.com/*\\"

Reference: https://learn.microsoft.com/en-us/graph/search-concept-files#example-5-use-filters-in-search-queries

https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference

Michael Han
  • 3,475
  • 1
  • 6
  • 8
  • Updated the `queryString` to `"queryString": "document path:\"https://contoso.sharepoint.com\""` is now able to filter the OneDrive files. Thanks @michael – WSI Appfactory Sep 14 '21 at 07:54
  • The `webUrl` returned from the API call looks like `downloadUrl` & it downloads the specific file/document. Is there any way to fetch the `previewUrl` (URL to open the specific document/file)? – WSI Appfactory Sep 14 '21 at 11:32