diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2023-05-11 13:08:57 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2023-07-07 17:43:46 +0200 |
commit | 837fd9f8da08c2c44a4e8af00d52d0622ca7dee2 (patch) | |
tree | ffbbf0a63833b325d4f46c446fcb80d794714c83 | |
parent | 5086dff5635a9a00501ece1056993f591fbf5a45 (diff) | |
download | nextcloud-server-837fd9f8da08c2c44a4e8af00d52d0622ca7dee2.tar.gz nextcloud-server-837fd9f8da08c2c44a4e8af00d52d0622ca7dee2.zip |
fix: favorites view and universal search against tags
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r-- | apps/dav/lib/Connector/Sabre/FilesReportPlugin.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Cache/QuerySearchHelper.php | 47 |
2 files changed, 33 insertions, 18 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php index c30c7bc51d0..7a53c34744c 100644 --- a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php @@ -234,8 +234,10 @@ class FilesReportPlugin extends ServerPlugin { // find sabre nodes by file id, restricted to the root node path $additionalNodes = $this->findNodesByFileIds($reportTargetNode, $resultFileIds); - if (!empty($additionalNodes)) { + if ($additionalNodes && $results) { $results = array_intersect($results, $additionalNodes); + } elseif (!$results && $additionalNodes) { + $results = $additionalNodes; } $filesUri = $this->getFilesBaseUri($uri, $reportTargetNode->getPath()); diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index ad86f3bd82b..d020ec00cea 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -39,6 +39,7 @@ use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; use OCP\Files\Search\ISearchQuery; use OCP\IDBConnection; +use OCP\IUser; use Psr\Log\LoggerInterface; class QuerySearchHelper { @@ -118,6 +119,29 @@ class QuerySearchHelper { return $tags; } + protected function equipQueryForSystemTags(CacheQueryBuilder $query): void { + $query + ->leftJoin('file', 'systemtag_object_mapping', 'systemtagmap', $query->expr()->andX( + $query->expr()->eq('file.fileid', $query->expr()->castColumn('systemtagmap.objectid', IQueryBuilder::PARAM_INT)), + $query->expr()->eq('systemtagmap.objecttype', $query->createNamedParameter('files')) + )) + ->leftJoin('systemtagmap', 'systemtag', 'systemtag', $query->expr()->andX( + $query->expr()->eq('systemtag.id', 'systemtagmap.systemtagid'), + $query->expr()->eq('systemtag.visibility', $query->createNamedParameter(true)) + )); + } + + protected function equipQueryForDavTags(CacheQueryBuilder $query, IUser $user): void { + $query + ->leftJoin('file', 'vcategory_to_object', 'tagmap', $query->expr()->eq('file.fileid', 'tagmap.objid')) + ->leftJoin('tagmap', 'vcategory', 'tag', $query->expr()->andX( + $query->expr()->eq('tagmap.type', 'tag.type'), + $query->expr()->eq('tagmap.categoryid', 'tag.id'), + $query->expr()->eq('tag.type', $query->createNamedParameter('files')), + $query->expr()->eq('tag.uid', $query->createNamedParameter($user->getUID())) + )); + } + /** * Perform a file system search in multiple caches * @@ -156,27 +180,16 @@ class QuerySearchHelper { if ($searchQuery->getSearchOperation() instanceof ISearchComparison) { switch ($searchQuery->getSearchOperation()->getField()) { case 'systemtag': - $query - ->leftJoin('file', 'systemtag_object_mapping', 'systemtagmap', $builder->expr()->andX( - $builder->expr()->eq('file.fileid', $builder->expr()->castColumn('systemtagmap.objectid', IQueryBuilder::PARAM_INT)), - $builder->expr()->eq('systemtagmap.objecttype', $builder->createNamedParameter('files')) - )) - ->leftJoin('systemtagmap', 'systemtag', 'systemtag', $builder->expr()->andX( - $builder->expr()->eq('systemtag.id', 'systemtagmap.systemtagid'), - $builder->expr()->eq('systemtag.visibility', $builder->createNamedParameter(true)) - )); + $this->equipQueryForSystemTags($query); break; case 'tagname': - $query - ->leftJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid')) - ->leftJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX( - $builder->expr()->eq('tagmap.type', 'tag.type'), - $builder->expr()->eq('tagmap.categoryid', 'tag.id'), - $builder->expr()->eq('tag.type', $builder->createNamedParameter('files')), - $builder->expr()->eq('tag.uid', $builder->createNamedParameter($user->getUID())) - )); + case 'favorite': + $this->equipQueryForDavTags($query, $user); break; } + } elseif ($searchQuery->getSearchOperation() instanceof SearchBinaryOperator) { + $this->equipQueryForSystemTags($query); + $this->equipQueryForDavTags($query, $user); } } |