Problem with file search

154 views
Skip to first unread message

Radek R

unread,
Jun 29, 2023, 10:35:30 AM6/29/23
to Google Apps Script Community
Hey,

I have the following problem:
I have access to one folder on Shared Drive that contains above 100 google documents.

I use something similar to the following script to list all docs that contain given word:
function searchFolderForDocs(word, folderId){
  const folder = DriveApp.getFolderById(folderId);
  const query = `fullText contains '${word}'`;
  const results = [];
  const filesIt = folder.searchFiles(query);

  while(filesIt.hasNext()){
    const file = filesIt.next();
    results.push([file.getName(), file.getId()]);
  }

  return results;
}

However this script does not return all the results. If I use searchbar from https://drive.google.com/drive/u/0/my-drive and type word in 'Includes the words' and folder in 'Location', I receive a lot of more results (all of them are valid). I would like to replicate the request that is send for that search. Investigating the network tab did not help me.

I tried to use Drive.FIles.list from Drive API (v2 and v3) and received the same results as for searchFiles method.

Any suggestions?

Thanks,
Radek


Tanaike

unread,
Jun 29, 2023, 9:40:28 PM6/29/23
to Google Apps Script Community
I think that in the case of `const filesIt = folder.searchFiles(query);`, the files just under the folder are searched without including the subfolders. Although I'm not sure about your actual situation, is this related to your current issue?

Radek R

unread,
Jun 30, 2023, 2:42:45 AM6/30/23
to Google Apps Script Community
Thanks for the response.

There are no subfolders in given folder, only google docs (some of them can have over 100 pages).

The searchbar from google drive generates the following url:
https://drive.google.com/drive/search?q=<word>%20parent:<folderId>
and this send request to:

scheme:
https

host
: clients6.google.com

filename:
/batch/drive/v2internal

GET /drive/v2internal/files?openDrive=false&reason=111&syncType=0&errorRecovery=false&q=fullText%20contains%20'<word>'%20and%20trashed%20%3D%20false%20and%20'<folderId>'%20in%20ancestors

However I was not able to get the same results in the apps script.

Tanaike

unread,
Jun 30, 2023, 3:53:08 AM6/30/23
to Google Apps Script Community
Thank you for replying. From your reply, I understood that your folder has no subfolders.

And, I have to apologize for my poor English skill. Unfortunately, I cannot understand the below the line of "There are no subfolders in given folder, only google docs (some of them can have over 100 pages).".

Radek R

unread,
Jun 30, 2023, 4:18:05 AM6/30/23
to Google Apps Script Community
I just wanted to write that in mentioned folder I store only google documents.
Reply all
Reply to author
Forward
0 new messages