From 01998978412f0fb1be752fb4905125e6c7837350 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Wed, 4 Nov 2020 10:32:06 +0100 Subject: [PATCH] beginning to implement search --- appinfo/info.xml | 11 ------- lib/AppInfo/Application.php | 2 ++ lib/Search/SearchProvider.php | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 lib/Search/SearchProvider.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 37457af..a1221e5 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -16,21 +16,10 @@ - - OCA\Radio\Command\Search - Radio radio.page.index - - - OCA\Radio\Activity\Setting - - - OCA\Radio\Activity\Provider - - diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 57075e0..3fecbeb 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace OCA\Radio\AppInfo; +use OCA\Radio\Search\SearchProvider; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -20,6 +21,7 @@ class Application extends App implements IBootstrap { public function register(IRegistrationContext $context): void { + $context->registerSearchProvider(SearchProvider::class); $context->registerService('request', static function ($c) { return $c->get(IRequest::class); }); diff --git a/lib/Search/SearchProvider.php b/lib/Search/SearchProvider.php new file mode 100644 index 0000000..e3be9f7 --- /dev/null +++ b/lib/Search/SearchProvider.php @@ -0,0 +1,59 @@ +url = $url; + } + + public function getId(): string { + return Application::APP_ID; + } + + public function getName(): string { + return 'Radio'; + } + + public function getOrder(string $route, array $routeParameters): int { + if (strpos($route, 'files' . '.') === 0) { + return 25; + } elseif (strpos($route, Application::APP_ID . '.') === 0) { + return -1; + } + return 4; + } + + public function search(IUser $user, ISearchQuery $query): SearchResult { + // create SearchResultEntry from Note + $result = [new SearchResultEntry( + '', + 'SRF Virus', + 'alternative, youth', + $this->url->linkToRouteAbsolute('radio.page.index') . 'search/' . urlencode($query->getTerm()), // FIXME: urlencode working? + 'icon-notes-trans' + )]; + return SearchResult::complete( + $this->getName(), + $result + ); + } +}