Python / Google Drive API - What is the difference between orderBy 'name' and orderBy 'name_natural'?

Viewed 321

According to Google API doc:

https://developers.google.com/drive/api/v3/reference/files/list

orderBy: A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'.

Please, what is the difference between 'name' and 'name_natural'?

Thanks for your help, Bests,

1 Answers

I think that name_natural might mean the natural sort. Ref For example, it supposes that the following files are put in a folder.

enter image description here

I thought that you might be able to understand about the difference between name_natural and name from the results using these sample files with name_natural and name.

1. name_natural order:

When the file list is retrieved with the following command,

curl \
  'https://www.googleapis.com/drive/v3/files?orderBy=name_natural&q=%27%23%23%23%27%20in%20parents&fields=files(name)' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed
  • In this case, orderBy, q and fields are name_natural, '{folderId}' in parents and files(name), respectively.

The following result is retrieved.

{"files":[
    {"name":"ss1"},
    {"name":"ss01"},
    {"name":"ss02"},
    {"name":"ss03"},
    {"name":"ss04"},
    {"name":"ss05"},
    {"name":"ss06"},
    {"name":"ss07"},
    {"name":"ss08"},
    {"name":"ss09"},
    {"name":"ss10"},
    {"name":"ss11"},
    {"name":"ss12"},
    {"name":"ss100"},
    {"name":"ss1000"}
]}
  • The file of ss1 is the top of the list.
  • The files of ss100 and ss1000 are the end of the list.
  • From this result and above sample image, it seems that the default sort by name of the interface on Google Drive is name_natural.

2. name order:

When the file list is retrieved with the following command,

curl \
  'https://www.googleapis.com/drive/v3/files?orderBy=name&q=%27%23%23%23%27%20in%20parents&fields=files(name)' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed
  • In this case, orderBy, q and fields are name, '{folderId}' in parents and files(name), respectively.

The following result is retrieved.

{"files":[
    {"name":"ss01"},
    {"name":"ss02"},
    {"name":"ss03"},
    {"name":"ss04"},
    {"name":"ss05"},
    {"name":"ss06"},
    {"name":"ss07"},
    {"name":"ss08"},
    {"name":"ss09"},
    {"name":"ss1"},
    {"name":"ss10"},
    {"name":"ss100"},
    {"name":"ss1000"},
    {"name":"ss11"},
    {"name":"ss12"}
]}
  • The file of ss1 is not the top of the list.
  • The files of ss100 and ss1000 are not the end of the list.

References:

Related