question

Rei-6137 avatar image
1 Vote"
Rei-6137 asked saldana-msft edited

Graph API Search for DriveItems within a drive does not return image files if I specify itemId

I'm using graph (Graph Explorer as well as my custom Azure Application which utilizes Graph API with the appropriate grants of Files.ReadWrite.All, Sites.ReadWrite.All) to search for specific files within a folder in a drive as documented here: https://docs.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http.

If I specify as follows it works:
/drives/{drive-id}/root/search(q='{search-text}')

However, if I specify the parent folder's Id, it returns empty or misses files (it seems it misses mostly png, jpg, adobe files):
/drives/{drive-id}/items/{folder-id}/search(q='{search-text}')

 {
     "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
     "value": []
 }

This is also true when I use the https://graph.microsoft.com/v1.0/search/query endpoint.
If I specify a path, it will not return results.

             "query": {
                 "queryString": "myfile path:\"https://contoso.sharepoint.com/sites/Library/Shared Documents/PATH\""
             }

But if specify no path, or the Document library level, it will return the image files.

             "query": {
                 "queryString": "myfile path:\"https://contoso.sharepoint.com/sites/Library/Shared Documents\""
             }

Funny thing is that it usually does actually successfully bring up text or PDF documents, but images like PNG and JPG often get lost. That is confusing to me as well. However if I do the drive root search, those images can be found. Is there a reason why when I specify the parent folder the graph api doesn't work properly? I've given it some time to index, but doesn't seem to change. Any help would be appreciated.

I also noticed that the webUrl on an image file is something like:
https://contoso.sharepoint.com/sites/LIBRARY/Shared Documents/Forms/DispForm.aspx?ID=2702

but a docx file is
https://contoso.sharepoint.com/sites/LIBRARY/Shared Documents/My Path/myfile.docx

I would appreciate any help on this.












sharepoint-devmicrosoft-graph-search
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SrinivasaRaoDarna-MSFT avatar image
2 Votes"
SrinivasaRaoDarna-MSFT answered SrinivasaRaoDarna-MSFT commented

Hi @Rei-6137 ,

From Search for DriveItems within a drive, I don't see any reference example for /drives/{drive-id}/items/{folder-id}/search(q='{search-text}') for test this scenario.

Using Search API, including ParentLink:/FolderName, along with Path should be able to retrieve files and images as well from a parent folder within a document library.

 POST https://graph.microsoft.com/v1.0/search/query
 {
 "requests": [
     {
         "entityTypes": [
             "driveItem"
         ],
         "query": {
             "queryString": "searchstring AND Path:https://contoso.sharepoint.com/sites/Library/Shared Documents AND ParentLink:/FolderName"
         }
     }
 ]
 }

Hope this helps.

If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, the ParentLink did it! However, I do not see this documented anywhere either. Is there a documentation that lists all the selectable properties on queryString?
Also, if we can do ParentLink by path, is there a Parent reference by parent Id? Something like

"AND ParentLink:015MZR2Q63HAASVH4XD5D3KTIPVVOJCOWF

1 Vote 1 ·

Hi @Rei-6137,

As the documentation search-concept-files-use-filters-in-search-queries,
In order to be valid, properties restriction should specify a valid, queryable managed property name in the condition.

Please refer SharePoint crawled-and-managed-properties-overview.
Hope this helps.

0 Votes 0 ·