Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(TagSearchProvider): Short circuit if no tag matches the query
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr authored and miaulalala committed Jul 6, 2023
commit 38bd09c96f186ba0232eda6c8767d04386ec40c3
10 changes: 6 additions & 4 deletions apps/systemtags/lib/Search/TagSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand All @@ -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) {
Expand All @@ -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(
Expand Down