diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-06-17 10:29:50 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-06-24 14:20:26 +0200 |
commit | f8e08a74bac4b065edcade762e2ca3632ff76797 (patch) | |
tree | 2a10c4612839850ab9d7791bd5d4c952992ee696 /apps | |
parent | 4488e846a526ed8de37e9756621b7c008d7a9466 (diff) | |
download | nextcloud-server-f8e08a74bac4b065edcade762e2ca3632ff76797.tar.gz nextcloud-server-f8e08a74bac4b065edcade762e2ca3632ff76797.zip |
Implement unified search for Files
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | apps/files/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | apps/files/lib/AppInfo/Application.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Search/FilesSearchProvider.php | 43 | ||||
-rw-r--r-- | apps/files/lib/Search/FilesSearchResultEntry.php | 37 |
5 files changed, 66 insertions, 21 deletions
diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index a4a72d59c13..04c24ee52d9 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -47,6 +47,8 @@ return array( 'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php', 'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', + 'OCA\\Files\\Search\\FilesSearchProvider' => $baseDir . '/../lib/Search/FilesSearchProvider.php', + 'OCA\\Files\\Search\\FilesSearchResultEntry' => $baseDir . '/../lib/Search/FilesSearchResultEntry.php', 'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php', diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index 91e29fac487..f9050eca862 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -62,6 +62,8 @@ class ComposerStaticInitFiles 'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php', 'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', + 'OCA\\Files\\Search\\FilesSearchProvider' => __DIR__ . '/..' . '/../lib/Search/FilesSearchProvider.php', + 'OCA\\Files\\Search\\FilesSearchResultEntry' => __DIR__ . '/..' . '/../lib/Search/FilesSearchResultEntry.php', 'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php', 'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php', diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 82562ffe9f0..5e473c411ee 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -44,6 +44,7 @@ use OCA\Files\Event\LoadSidebar; use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter; use OCA\Files\Listener\LoadSidebarListener; use OCA\Files\Notification\Notifier; +use OCA\Files\Search\FilesSearchProvider; use OCA\Files\Service\TagService; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -106,6 +107,8 @@ class Application extends App implements IBootstrap { $context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class); $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); + + $context->registerSearchProvider(FilesSearchProvider::class); } public function boot(IBootContext $context): void { diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index 0a360d6f81c..3f1c4de0aa1 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -25,7 +25,10 @@ declare(strict_types=1); namespace OCA\Files\Search; +use OC\Search\Provider\File; +use OC\Search\Result\File as FileResult; use OCP\IL10N; +use OCP\IURLGenerator; use OCP\IUser; use OCP\Search\IProvider; use OCP\Search\ISearchQuery; @@ -33,11 +36,21 @@ use OCP\Search\SearchResult; class FilesSearchProvider implements IProvider { + /** @var File */ + private $fileSearch; + /** @var IL10N */ private $l10n; - public function __construct(IL10N $l10n) { + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(File $fileSearch, + IL10N $l10n, + IURLGenerator $urlGenerator) { $this->l10n = $l10n; + $this->fileSearch = $fileSearch; + $this->urlGenerator = $urlGenerator; } public function getId(): string { @@ -47,26 +60,14 @@ class FilesSearchProvider implements IProvider { public function search(IUser $user, ISearchQuery $query): SearchResult { return SearchResult::complete( $this->l10n->t('Files'), - [ - new FilesSearchResultEntry( - "path/to/icon.png", - "cute cats.jpg", - "/Cats", - "/f/21156" - ), - new FilesSearchResultEntry( - "path/to/icon.png", - "cat 1.jpg", - "/Cats", - "/f/21192" - ), - new FilesSearchResultEntry( - "path/to/icon.png", - "cat 2.jpg", - "/Cats", - "/f/25942" - ), - ] + array_map(function (FileResult $result) { + return new FilesSearchResultEntry( + $this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]), + $result->name, + $result->path, + $result->link + ); + }, $this->fileSearch->search($query->getTerm())) ); } } diff --git a/apps/files/lib/Search/FilesSearchResultEntry.php b/apps/files/lib/Search/FilesSearchResultEntry.php new file mode 100644 index 00000000000..c4f6e491d6f --- /dev/null +++ b/apps/files/lib/Search/FilesSearchResultEntry.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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 <http://www.gnu.org/licenses/>. + */ + +namespace OCA\Files\Search; + +use OCP\Search\ASearchResultEntry; + +class FilesSearchResultEntry extends ASearchResultEntry { + public function __construct(string $thumbnailUrl, + string $filename, + string $path, + string $url) { + parent::__construct($thumbnailUrl, $filename, $path, $url); + } +} |