diff options
author | Robin Appelman <robin@icewind.nl> | 2021-05-07 15:38:11 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-06-14 17:11:36 +0300 |
commit | f938daa6e4e37a7418a978926204e7fdec3b1640 (patch) | |
tree | fa3b85869f891ad6987ef18f7920439e21981f22 /lib | |
parent | 27e50b24aab60112c05f88e570af099faeac0122 (diff) |
update tests and fix some edge cases around new search
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Cache/QuerySearchHelper.php | 6 | ||||
-rw-r--r-- | lib/private/Files/Node/Folder.php | 27 |
2 files changed, 27 insertions, 6 deletions
diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 393eb54e4fe..c16d660051e 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -242,7 +242,11 @@ class QuerySearchHelper { */ public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders) { foreach ($orders as $order) { - $query->addOrderBy($order->getField(), $order->getDirection()); + $field = $order->getField(); + if ($field === 'fileid') { + $field = 'file.fileid'; + } + $query->addOrderBy($field, $order->getDirection()); } } 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); |