further improvements to unified search
This commit is contained in:
parent
4926be0afa
commit
40c83d79ee
@ -12,16 +12,23 @@ use OCP\Search\ISearchQuery;
|
|||||||
use OCP\Search\SearchResult;
|
use OCP\Search\SearchResult;
|
||||||
use OCP\Search\SearchResultEntry;
|
use OCP\Search\SearchResultEntry;
|
||||||
|
|
||||||
|
use OCP\Http\Client\IClientService;
|
||||||
|
|
||||||
use function urlencode;
|
use function urlencode;
|
||||||
|
|
||||||
class SearchProvider implements IProvider {
|
class SearchProvider implements IProvider {
|
||||||
|
|
||||||
|
/** @var IClientService */
|
||||||
|
private $clientService;
|
||||||
|
|
||||||
/** @var IURLGenerator */
|
/** @var IURLGenerator */
|
||||||
private $url;
|
private $url;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
IClientService $clientService,
|
||||||
IURLGenerator $url
|
IURLGenerator $url
|
||||||
) {
|
) {
|
||||||
|
$this->clientService = $clientService;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,14 +50,37 @@ class SearchProvider implements IProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function search(IUser $user, ISearchQuery $query): SearchResult {
|
public function search(IUser $user, ISearchQuery $query): SearchResult {
|
||||||
// create SearchResultEntry from Note
|
|
||||||
$result = [new SearchResultEntry(
|
$term = $query->getTerm();
|
||||||
'',
|
$url = "https://de1.api.radio-browser.info/json/stations/byname/" . $term;
|
||||||
'SRF Virus',
|
|
||||||
'alternative, youth',
|
$client = $this->clientService->newClient();
|
||||||
$this->url->linkToRouteAbsolute('radio.page.index') . 'search/' . urlencode($query->getTerm()), // FIXME: urlencode working?
|
try {
|
||||||
|
$response = $client->get($url);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->logger->error("Could not search for radio stations: " . $e->getMessage());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
$body = $response->getBody();
|
||||||
|
$parsed = json_decode($body, true);
|
||||||
|
|
||||||
|
$result = array_map(function (array $result) {
|
||||||
|
return new SearchResultEntry(
|
||||||
|
$result['favicon'],
|
||||||
|
$result['name'],
|
||||||
|
$result['tags'],
|
||||||
|
'#/search/virus',
|
||||||
'icon-notes-trans'
|
'icon-notes-trans'
|
||||||
)];
|
);
|
||||||
|
}, $parsed);
|
||||||
|
|
||||||
|
// $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(
|
return SearchResult::complete(
|
||||||
$this->getName(),
|
$this->getName(),
|
||||||
$result
|
$result
|
||||||
|
Loading…
Reference in New Issue
Block a user