diff options
author | Robin Appelman <robin@icewind.nl> | 2021-05-07 14:38:11 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-06-14 16:11:36 +0200 |
commit | f938daa6e4e37a7418a978926204e7fdec3b1640 (patch) | |
tree | fa3b85869f891ad6987ef18f7920439e21981f22 /lib/private/Files/Node | |
parent | 27e50b24aab60112c05f88e570af099faeac0122 (diff) | |
download | nextcloud-server-f938daa6e4e37a7418a978926204e7fdec3b1640.tar.gz nextcloud-server-f938daa6e4e37a7418a978926204e7fdec3b1640.zip |
update tests and fix some edge cases around new search
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Node')
-rw-r--r-- | lib/private/Files/Node/Folder.php | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index eb4841c5719..7b480a60955 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -30,11 +30,9 @@ */ namespace OC\Files\Node; -use OC\DB\QueryBuilder\Literal; use OC\Files\Cache\QuerySearchHelper; use OC\Files\Search\SearchBinaryOperator; use OC\Files\Cache\Wrapper\CacheJail; -use OC\Files\Search\SearchBinaryOperator; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchOrder; use OC\Files\Search\SearchQuery; @@ -250,7 +248,12 @@ class Folder extends Node implements \OCP\Files\Folder { // collect all caches for this folder, indexed by their mountpoint relative to this folder // and save the mount which is needed later to construct the FileInfo objects - $caches = ['' => new CacheJail($storage->getCache(''), $internalPath)]; // a temporary CacheJail is used to handle filtering down the results to within this folder + if ($internalPath !== '') { + // a temporary CacheJail is used to handle filtering down the results to within this folder + $caches = ['' => new CacheJail($storage->getCache(''), $internalPath)]; + } else { + $caches = ['' => $storage->getCache('')]; + } $mountByMountPoint = ['' => $mount]; if (!$limitToHome) { @@ -270,13 +273,27 @@ class Folder extends Node implements \OCP\Files\Folder { $resultsPerCache = $searchHelper->searchInCaches($query, $caches); // loop trough all results per-cache, constructing the FileInfo object from the CacheEntry and merge them all - $files = array_merge(...array_map(function(array $results, $relativeMountPoint) use ($mountByMountPoint) { + $files = array_merge(...array_map(function (array $results, $relativeMountPoint) use ($mountByMountPoint) { $mount = $mountByMountPoint[$relativeMountPoint]; - return array_map(function(ICacheEntry $result) use ($relativeMountPoint, $mount) { + return array_map(function (ICacheEntry $result) use ($relativeMountPoint, $mount) { return $this->cacheEntryToFileInfo($mount, $relativeMountPoint, $result); }, $results); }, array_values($resultsPerCache), array_keys($resultsPerCache))); + // since results were returned per-cache, they are no longer fully sorted + $order = $query->getOrder(); + if ($order) { + usort($files, function (FileInfo $a, FileInfo $b) use ($order) { + foreach ($order as $orderField) { + $cmp = $orderField->sortFileInfo($a, $b); + if ($cmp !== 0) { + return $cmp; + } + } + return 0; + }); + } + return array_map(function (FileInfo $file) { return $this->createNode($file->getPath(), $file); }, $files); |