diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2020-12-04 08:42:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-04 08:42:15 +0100 |
commit | 32ded877dc30b18f6eba7f3854988ce2992feb00 (patch) | |
tree | 56018cd5f1a08d8627753c6d693ef8a5a919a47d | |
parent | 3f88dbd25956897440ab0e34053551a77a1e922f (diff) | |
parent | 885dabb761c283be61ea4dd96e04146c98c02d1c (diff) | |
download | nextcloud-server-32ded877dc30b18f6eba7f3854988ce2992feb00.tar.gz nextcloud-server-32ded877dc30b18f6eba7f3854988ce2992feb00.zip |
Merge pull request #24474 from nextcloud/enhancement/unified-search-result-attributes
Allow unified search results to have attributes
-rw-r--r-- | apps/files/lib/Search/FilesSearchProvider.php | 5 | ||||
-rw-r--r-- | lib/public/Search/SearchResultEntry.php | 21 |
2 files changed, 25 insertions, 1 deletions
diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index 5c97e771ab7..a3c6120ef13 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -110,13 +110,16 @@ class FilesSearchProvider implements IProvider { ? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]) : ''; - return new SearchResultEntry( + $searchResultEntry = new SearchResultEntry( $thumbnailUrl, $result->name, $this->formatSubline($result), $this->urlGenerator->getAbsoluteURL($result->link), $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type) ); + $searchResultEntry->addAttribute('fileId', (string)$result->id); + $searchResultEntry->addAttribute('path', $result->path); + return $searchResultEntry; }, $this->fileSearch->search($query->getTerm())) ); } diff --git a/lib/public/Search/SearchResultEntry.php b/lib/public/Search/SearchResultEntry.php index b661ced5014..347c3fcd289 100644 --- a/lib/public/Search/SearchResultEntry.php +++ b/lib/public/Search/SearchResultEntry.php @@ -83,6 +83,13 @@ class SearchResultEntry implements JsonSerializable { protected $rounded; /** + * @var string[] + * @psalm-var array<string, string> + * @since 20.0.0 + */ + protected $attributes = []; + + /** * @param string $thumbnailUrl a relative or absolute URL to the thumbnail or icon of the entry * @param string $title a main title of the entry * @param string $subline the secondary line of the entry @@ -107,6 +114,19 @@ class SearchResultEntry implements JsonSerializable { } /** + * Add optional attributes to the result entry, e.g. an ID or some other + * context information that can be read by the client application + * + * @param string $key + * @param string $value + * + * @since 20.0.0 + */ + public function addAttribute(string $key, string $value): void { + $this->attributes[$key] = $value; + } + + /** * @return array * * @since 20.0.0 @@ -119,6 +139,7 @@ class SearchResultEntry implements JsonSerializable { 'resourceUrl' => $this->resourceUrl, 'icon' => $this->icon, 'rounded' => $this->rounded, + 'attributes' => $this->attributes, ]; } } |