]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: favorites view and universal search against tags
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Thu, 11 May 2023 11:08:57 +0000 (13:08 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 21 Jun 2023 16:19:08 +0000 (18:19 +0200)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
lib/private/Files/Cache/QuerySearchHelper.php

index c30c7bc51d00944ff169b9dd530a89190ac2a098..7a53c34744cf55b076d8bb012216309a30c1066c 100644 (file)
@@ -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());
index e2a9572c5f7d088dfa2d3322d4c95764129ee325..0f9c6eeaa880f252207e6fb4dc252cd1c47ad1ed 100644 (file)
@@ -40,6 +40,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);
                        }
                }