From 38bd09c96f186ba0232eda6c8767d04386ec40c3 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 29 Jun 2023 15:01:14 +0200 Subject: [PATCH 1/2] fix(TagSearchProvider): Short circuit if no tag matches the query Signed-off-by: Marcel Klehr --- apps/systemtags/lib/Search/TagSearchProvider.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/systemtags/lib/Search/TagSearchProvider.php b/apps/systemtags/lib/Search/TagSearchProvider.php index 7a7cb0b061c49..d775629b67447 100644 --- a/apps/systemtags/lib/Search/TagSearchProvider.php +++ b/apps/systemtags/lib/Search/TagSearchProvider.php @@ -113,6 +113,11 @@ public function getOrder(string $route, array $routeParameters): int { * @inheritDoc */ public function search(IUser $user, ISearchQuery $query): SearchResult { + $matchingTags = $this->tagManager->getAllTags(1, $query->getTerm()); + if (count($matchingTags) === 0) { + return SearchResult::complete($this->l10n->t('Tags'), []); + } + $userFolder = $this->rootFolder->getUserFolder($user->getUID()); $fileQuery = new SearchQuery( new SearchBinaryOperator(SearchBinaryOperator::OPERATOR_OR, [ @@ -133,7 +138,6 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { return $node->getId(); }, $searchResults); $matchedTags = $this->objectMapper->getTagIdsForObjects($resultIds, 'files'); - $relevantTags = $this->tagManager->getTagsByIds(array_unique($this->flattenArray($matchedTags))); // prepare direct tag results $tagResults = array_map(function(ISystemTag $tag) { @@ -149,9 +153,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { 'icon-tag' ); return $searchResultEntry; - }, array_filter($relevantTags, function($tag) use ($query) { - return $tag->isUserVisible() && strpos($tag->getName(), $query->getTerm()) !== false; - })); + }, $matchingTags); // prepare files results return SearchResult::paginated( From 656d54f51fa137fe7a06e2c9af70958be86a07b1 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Fri, 30 Jun 2023 12:32:14 +0200 Subject: [PATCH 2/2] Fix psalm error Signed-off-by: Marcel Klehr --- apps/systemtags/lib/Search/TagSearchProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/systemtags/lib/Search/TagSearchProvider.php b/apps/systemtags/lib/Search/TagSearchProvider.php index d775629b67447..5c731e42cc3e0 100644 --- a/apps/systemtags/lib/Search/TagSearchProvider.php +++ b/apps/systemtags/lib/Search/TagSearchProvider.php @@ -113,7 +113,7 @@ public function getOrder(string $route, array $routeParameters): int { * @inheritDoc */ public function search(IUser $user, ISearchQuery $query): SearchResult { - $matchingTags = $this->tagManager->getAllTags(1, $query->getTerm()); + $matchingTags = $this->tagManager->getAllTags(true, $query->getTerm()); if (count($matchingTags) === 0) { return SearchResult::complete($this->l10n->t('Tags'), []); }