From 16179624914f8fba705da70f3bbd4f30ac9412be Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 27 Nov 2020 10:29:51 +0100 Subject: [PATCH 1/4] Make it possible to return a search object result (with type and ID) Signed-off-by: Christoph Wurst --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/public/Search/ObjectSearchResultEntry.php | 92 +++++++++++++++++++ lib/public/Search/SearchResultEntry.php | 2 +- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 lib/public/Search/ObjectSearchResultEntry.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 4f04d90b22b85..a37d05bde7fee 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -446,6 +446,7 @@ 'OCP\\SabrePluginException' => $baseDir . '/lib/public/SabrePluginException.php', 'OCP\\Search\\IProvider' => $baseDir . '/lib/public/Search/IProvider.php', 'OCP\\Search\\ISearchQuery' => $baseDir . '/lib/public/Search/ISearchQuery.php', + 'OCP\\Search\\ObjectSearchResultEntry' => $baseDir . '/lib/public/Search/ObjectSearchResultEntry.php', 'OCP\\Search\\PagedProvider' => $baseDir . '/lib/public/Search/PagedProvider.php', 'OCP\\Search\\Provider' => $baseDir . '/lib/public/Search/Provider.php', 'OCP\\Search\\Result' => $baseDir . '/lib/public/Search/Result.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 2797276757646..fec1fa3dea015 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -475,6 +475,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\SabrePluginException' => __DIR__ . '/../../..' . '/lib/public/SabrePluginException.php', 'OCP\\Search\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Search/IProvider.php', 'OCP\\Search\\ISearchQuery' => __DIR__ . '/../../..' . '/lib/public/Search/ISearchQuery.php', + 'OCP\\Search\\ObjectSearchResultEntry' => __DIR__ . '/../../..' . '/lib/public/Search/ObjectSearchResultEntry.php', 'OCP\\Search\\PagedProvider' => __DIR__ . '/../../..' . '/lib/public/Search/PagedProvider.php', 'OCP\\Search\\Provider' => __DIR__ . '/../../..' . '/lib/public/Search/Provider.php', 'OCP\\Search\\Result' => __DIR__ . '/../../..' . '/lib/public/Search/Result.php', diff --git a/lib/public/Search/ObjectSearchResultEntry.php b/lib/public/Search/ObjectSearchResultEntry.php new file mode 100644 index 0000000000000..bdbbb632a7f50 --- /dev/null +++ b/lib/public/Search/ObjectSearchResultEntry.php @@ -0,0 +1,92 @@ + + * + * @author 2020 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\Search; + +use function array_merge; + +/** + * @since 20.0.0 + */ +class ObjectSearchResultEntry extends SearchResultEntry { + + /** + * @var string + * @since 20.0.0 + */ + protected $objectType; + + /** + * @var string + * @since 20.0.0 + */ + protected $objectId; + + /** + * @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 + * @param string $resourceUrl the URL where the user can find the detail, like a deep link inside the app + * @param string $icon the icon class or url to the icon + * @param boolean $rounded is the thumbnail rounded + * + * @since 20.0.0 + */ + public function __construct(string $thumbnailUrl, + string $title, + string $subline, + string $resourceUrl, + string $objectType, + string $objectId, + string $icon = '', + bool $rounded = false) { + parent::__construct( + $thumbnailUrl, + $title, + $subline, + $resourceUrl, + $icon, + $rounded + ); + + $this->objectType = $objectType; + $this->objectId = $objectId; + } + + /** + * @return mixed[] + * + * @since 20.0.0 + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + 'objectType' => $this->objectType, + 'objectId' => $this->objectId, + ] + ); + } +} diff --git a/lib/public/Search/SearchResultEntry.php b/lib/public/Search/SearchResultEntry.php index b661ced5014d9..9052d052b6de2 100644 --- a/lib/public/Search/SearchResultEntry.php +++ b/lib/public/Search/SearchResultEntry.php @@ -107,7 +107,7 @@ public function __construct(string $thumbnailUrl, } /** - * @return array + * @return mixed[] * * @since 20.0.0 */ From 71388e8a7498e7d8bd175f86455cb82a8223f113 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 27 Nov 2020 10:33:26 +0100 Subject: [PATCH 2/4] Add file IDs for file search results Signed-off-by: Christoph Wurst --- apps/files/lib/Search/FilesSearchProvider.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index 5c97e771ab7fc..e617669a44e17 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -37,6 +37,7 @@ use OCP\IUser; use OCP\Search\IProvider; use OCP\Search\ISearchQuery; +use OCP\Search\ObjectSearchResultEntry; use OCP\Search\SearchResult; use OCP\Search\SearchResultEntry; @@ -110,11 +111,13 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { ? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]) : ''; - return new SearchResultEntry( + return new ObjectSearchResultEntry( $thumbnailUrl, $result->name, $this->formatSubline($result), $this->urlGenerator->getAbsoluteURL($result->link), + 'file', + $result->id, $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type) ); }, $this->fileSearch->search($query->getTerm())) From 87fdd8d3e2e46498e0317ba9ea17c13b9f588808 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 27 Nov 2020 10:46:49 +0100 Subject: [PATCH 3/4] fixup! Add file IDs for file search results Signed-off-by: Christoph Wurst --- apps/files/lib/Search/FilesSearchProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index e617669a44e17..a2cdafcc015cf 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -39,7 +39,6 @@ use OCP\Search\ISearchQuery; use OCP\Search\ObjectSearchResultEntry; use OCP\Search\SearchResult; -use OCP\Search\SearchResultEntry; class FilesSearchProvider implements IProvider { From b8177d22da58f4081f0f49679ae3e3b291f1115f Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 27 Nov 2020 10:50:37 +0100 Subject: [PATCH 4/4] fixup! Add file IDs for file search results Signed-off-by: Christoph Wurst --- apps/files/lib/Search/FilesSearchProvider.php | 2 +- lib/public/Search/Result.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index a2cdafcc015cf..cd3ec8168b788 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -116,7 +116,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { $this->formatSubline($result), $this->urlGenerator->getAbsoluteURL($result->link), 'file', - $result->id, + (string)$result->id, $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type) ); }, $this->fileSearch->search($query->getTerm())) diff --git a/lib/public/Search/Result.php b/lib/public/Search/Result.php index a3a58a38cde9d..47c2641a5fd83 100644 --- a/lib/public/Search/Result.php +++ b/lib/public/Search/Result.php @@ -36,7 +36,7 @@ class Result { /** * A unique identifier for the result, usually given as the item ID in its * corresponding application. - * @var string + * @var string|int * @since 7.0.0 * @deprecated 20.0.0 */