beginning to implement search

This commit is contained in:
Jonas Heinrich 2020-11-04 10:32:06 +01:00
parent d21ea0b78c
commit 0199897841
3 changed files with 61 additions and 11 deletions

View File

@ -16,21 +16,10 @@
<dependencies> <dependencies>
<nextcloud min-version="20" max-version="20"/> <nextcloud min-version="20" max-version="20"/>
</dependencies> </dependencies>
<commands>
<command>OCA\Radio\Command\Search</command>
</commands>
<navigations> <navigations>
<navigation> <navigation>
<name>Radio</name> <name>Radio</name>
<route>radio.page.index</route> <route>radio.page.index</route>
</navigation> </navigation>
</navigations> </navigations>
<activity>
<settings>
<setting>OCA\Radio\Activity\Setting</setting>
</settings>
<providers>
<provider>OCA\Radio\Activity\Provider</provider>
</providers>
</activity>
</info> </info>

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\Radio\AppInfo; namespace OCA\Radio\AppInfo;
use OCA\Radio\Search\SearchProvider;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
@ -20,6 +21,7 @@ class Application extends App implements IBootstrap {
public function register(IRegistrationContext $context): void { public function register(IRegistrationContext $context): void {
$context->registerSearchProvider(SearchProvider::class);
$context->registerService('request', static function ($c) { $context->registerService('request', static function ($c) {
return $c->get(IRequest::class); return $c->get(IRequest::class);
}); });

View File

@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace OCA\Radio\Search;
use OCA\Radio\AppInfo\Application;
use OCP\IUser;
use OCP\IURLGenerator;
use OCP\Search\IProvider;
use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
use OCP\Search\SearchResultEntry;
use function urlencode;
class SearchProvider implements IProvider {
/** @var IURLGenerator */
private $url;
public function __construct(
IURLGenerator $url
) {
$this->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
);
}
}