Posting this here because I have found no note or solution elsewhere on the web.
I am currently experiencing a discrepancy between search results when using the drive search toolbar and the DriveApp.searchFiles()
functionality of apps scripts as follows.
The drive search bar always returns complete results for a given query [looking at all text within a document and in the title], but DriveApp.searchFiles()
does not. Certain files are missing/not returned.
Upon finding a given file that is returned from the drive search bar ONLY (one that was not being returned by the DriveApp search) and opening it, it then starts appearing/being returned by DriveApp.searchFiles()
.
This issue further seems to be a user-specific one. The script we are developing is used by multiple users and new users (ones that are added to an extant file system and then given our tool) experience this issue for a majority of files. After which, when they open a given 'missing' file, it begins appearing in the search results once more.
For reference, my code is as follows:
var targetParam = 'title contains "'+target+'" or fullText contains "'+target+'"';
var searchResults = DriveApp.searchFiles(targetParam);
In all instances of this issue, the drive search bar returns a complete list and opening a given file 'fixes' its issue. Given the scale of what we are trying to do it is not a possibility to have every user open every file.
For clarification, these files are within a large file system in either team drives or traditional G suite. Users are given access by being added to the highest level file, to the team drive, or by being added to a user group that has access to the file system already. All users are within our domain.
Is this a known discrepancy? Is there something that I may be doing wrong in my search query to cause this? I am interested in any potential solutions or ideas.