Specification of Search Query for File List Method in Drive API

Gists

In this report, I would like to report about the current specification of the search query for the file list method in Drive API.

Recently, I noticed that the specification of the search query for the file list method in Drive API might have been changed. I thought that to know the change of specification of the search query is important for creating the application using Drive API. In this report, I would like to introduce the current specification of the search query.

Experiments

I have done the following 5 experiments.

  1. Retrieving the file list by searching the filename.
  2. Retrieving the file list by searching the mimeType.
  3. Retrieving the file list by searching the parent folder ID.
  4. Retrieving the file list by searching the trash box.
  5. Retrieving the file list by searching the properties.

As the operators for the search query, in the current stage (April 27, 2021), there are contains, =, !=, <=, <, >, >=, in, has. In this experiments, in order to retrieve the file list which has the inputted value, the operators of contains, =, in, has were used.


1. Retrieving the file list by searching the filename.

At the official document, when the file is searched by the filename, name and contains, =, != are used. So in this case, the combination for checking this search query, I prepare the following 6 parts.

"name", "contains", "=", "in", "has", "'###filename###'"

When 3 parts like name = 'filename' for searching the files with the filename are retrieved from above 6 parts, 120 patterns can be considered. When these 120 patterns were checked for the method of file list of Drive API v3, it was found that in order to search the filename, the following search queries could be used. And, I could confirm that those search query returns the same results and those were the correct values. For other patterns, an error like Invalid Value occurred.

  1. name = 'sampleFilename'
  2. name contains 'sampleFilename'
  3. name in 'sampleFilename'

The operators using at 1 and 2 can follow to the official document. But the operator using at 3 is not seen in the official document. It is considered that this is the hidden search query.


2. Retrieving the file list by searching the mimeType.

At the official document, when the file is searched by the mimeType, mimeType and contains1, =, != are used. So in this case, the combination for checking this search query, I prepare the following 6 parts.

"mimeType", "=", "in", "contains", "has", "'###mimeType###'"

When 3 parts like mimeType = 'mimeType' for searching the files with the mimeType are retrieved from above 6 parts, 120 patterns can be considered. When these 120 patterns were checked for the method of file list of Drive API v3, it was found that in order to search the mimeType, the following search queries could be used. And, I could confirm that those search query returns the same results and those were the correct values. For other patterns, an error like Invalid Value occurred.

  1. mimeType = 'mimeType'
  2. mimeType contains 'mimeType'
  3. mimeType in 'mimeType'

The operators using at 1 and 2 can follow to the official document. But the operator using at 3 is not seen in the official document. It is considered that this is the hidden search query.


3. Retrieving the file list by searching the parent folder ID.

At the official document, when the file is searched by the parent folder ID, parents and in are used. So in this case, the combination for checking this search query, I prepare the following 6 parts.

"parents", "=", "in", "contains", "has", "'###folderId###'"

When 3 parts like '###folderId###' in parents for searching the files in the folder of folder ID are retrieved from above 6 parts, 120 patterns can be considered. When these 120 patterns were checked for the method of file list of Drive API v3, it was found that in order to search the file list in the folder, the following search queries could be used. And, I could confirm that those search query returns the same results and those were the correct values. For other patterns, an error like Invalid Value occurred.

  1. '###folderId###' in parents
  2. parents = '###folderId###'
  3. parents in '###folderId###'

Pattern 1 can follow to the official document. But the patterns 2 and 3 are not seen in the official document. It is considered that these are the hidden search query.


4. Retrieving the file list in trash box.

At the official document, when the file is searched by the parent folder ID, trashed and in are used. So in this case, the combination for checking this search query, I prepare the following 6 parts.

"trashed", "=", "in", "contains", "has", "true"

When 3 parts like trashed = true for searching the files in the trash box are retrieved from above 6 parts, 120 patterns can be considered. When these 120 patterns were checked for the method of file list of Drive API v3, it was found that in order to search the file list in the trash box, the following search queries could be used. And, I could confirm that those search query returns the same results and those were the correct values. For other patterns, an error like Invalid Value occurred.

  1. trashed = true
  2. trashed in true

Pattern 1 can follow to the official document. But the pattern 2 is not seen in the official document. It is considered that this is the hidden search query.


5. Retrieving the file list by searching properties.

At the official document, when the file is searched by the properties, properties and has are used. So in this case, the combination for checking this search query, I prepare the following 6 parts.

"properties", "=", "in", "contains", "has", "{ key='key' and value='value' }"

When 3 parts like properties has { key='key' and value='value' } for searching the files by the properties are retrieved from above 6 parts, 120 patterns can be considered. When these 120 patterns were checked for the method of file list of Drive API v3, it was found that in order to search the file list by the properties, the following search queries could be used. And, I could confirm that those search query returns the same results and those were the correct values. For other patterns, an error like Invalid Value occurred.

  1. properties has { key='key' and value='value' }

In this case, only pattern 1 could work. This can follow to the official document.

Summary

  • From above results, it was found that the operators of = and in can be used as the same operator. But, it was also found that the operator of has can use for properties and appProperties.

References

As the references, the official documents for the search query are as follows.

 Share!