diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index 5c97e771ab7fc..cd3ec8168b788 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -37,8 +37,8 @@ use OCP\IUser; use OCP\Search\IProvider; use OCP\Search\ISearchQuery; +use OCP\Search\ObjectSearchResultEntry; use OCP\Search\SearchResult; -use OCP\Search\SearchResultEntry; class FilesSearchProvider implements IProvider { @@ -110,11 +110,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', + (string)$result->id, $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type) ); }, $this->fileSearch->search($query->getTerm())) 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/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 */ 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 */