diff --git a/apps/comments/lib/Search/CommentsSearchProvider.php b/apps/comments/lib/Search/CommentsSearchProvider.php
index 87a658cab1c6c..25117de9e8bf4 100644
--- a/apps/comments/lib/Search/CommentsSearchProvider.php
+++ b/apps/comments/lib/Search/CommentsSearchProvider.php
@@ -17,7 +17,6 @@
use OCP\Search\SearchResult;
use OCP\Search\SearchResultEntry;
use function array_map;
-use function pathinfo;
class CommentsSearchProvider implements IProvider {
public function __construct(
@@ -49,22 +48,25 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$this->l10n->t('Comments'),
array_map(function (Result $result) {
$path = $result->path;
- $pathInfo = pathinfo($path);
$isUser = $this->userManager->userExists($result->authorId);
$avatarUrl = $isUser
? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42])
: $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]);
- return new SearchResultEntry(
+ $link = $this->urlGenerator->linkToRoute(
+ 'files.View.showFile',
+ ['fileid' => $result->fileId]
+ );
+ $searchResultEntry = new SearchResultEntry(
$avatarUrl,
$result->name,
$path,
- $this->urlGenerator->linkToRouteAbsolute('files.view.index', [
- 'dir' => $pathInfo['dirname'],
- 'scrollto' => $pathInfo['basename'],
- ]),
+ $link,
'',
true
);
+ $searchResultEntry->addAttribute('fileId', (string)$result->fileId);
+ $searchResultEntry->addAttribute('path', $path);
+ return $searchResultEntry;
}, $this->legacyProvider->search($query->getTerm()))
);
}
diff --git a/apps/comments/lib/Search/LegacyProvider.php b/apps/comments/lib/Search/LegacyProvider.php
index a269c418d0657..4e71c202bb009 100644
--- a/apps/comments/lib/Search/LegacyProvider.php
+++ b/apps/comments/lib/Search/LegacyProvider.php
@@ -11,6 +11,7 @@
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Files\Folder;
+use OCP\Files\InvalidPathException;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IUser;
@@ -61,9 +62,10 @@ public function search($query): array {
$result[] = new Result($query,
$comment,
$displayName,
- $file->getPath()
+ $file->getPath(),
+ $file->getId(),
);
- } catch (NotFoundException $e) {
+ } catch (NotFoundException|InvalidPathException $e) {
continue;
}
}
diff --git a/apps/comments/lib/Search/Result.php b/apps/comments/lib/Search/Result.php
index 7478c110d634b..13907757954eb 100644
--- a/apps/comments/lib/Search/Result.php
+++ b/apps/comments/lib/Search/Result.php
@@ -34,6 +34,10 @@ class Result extends BaseResult {
* @deprecated 20.0.0
*/
public $fileName;
+ /**
+ * @deprecated 20.0.0
+ */
+ public int $fileId;
/**
* @throws NotFoundException
@@ -47,6 +51,7 @@ public function __construct(
*/
public string $authorName,
string $path,
+ int $fileId,
) {
parent::__construct(
$comment->getId(),
@@ -58,6 +63,7 @@ public function __construct(
$this->authorId = $comment->getActorId();
$this->fileName = basename($path);
$this->path = $this->getVisiblePath($path);
+ $this->fileId = $fileId;
}
/**
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index 4f74562719b60..44176b2bfd038 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -71,6 +71,8 @@
authorId]]>
authorId]]>
authorId]]>
+ fileId]]>
+ fileId]]>
name]]>
path]]>
@@ -81,7 +83,8 @@
getPath()
+ $file->getPath(),
+ $file->getId(),
)]]>
@@ -108,6 +111,7 @@
authorId]]>
comment]]>
+ fileId]]>
fileName]]>
path]]>