1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- declare(strict_types=1);
- namespace OC\Core\Controller;
- use OCP\AppFramework\Controller;
- use OCP\AppFramework\Http\Attribute\FrontpageRoute;
- use OCP\AppFramework\Http\JSONResponse;
- use OCP\IRequest;
- use OCP\ISearch;
- use OCP\Search\Result;
- use Psr\Log\LoggerInterface;
- class SearchController extends Controller {
- public function __construct(
- string $appName,
- IRequest $request,
- private ISearch $searcher,
- private LoggerInterface $logger,
- ) {
- parent::__construct($appName, $request);
- }
-
-
- public function search(string $query, array $inApps = [], int $page = 1, int $size = 30): JSONResponse {
- $results = $this->searcher->searchPaged($query, $inApps, $page, $size);
- $results = array_filter($results, function (Result $result) {
- if (json_encode($result, JSON_HEX_TAG) === false) {
- $this->logger->warning("Skipping search result due to invalid encoding: {type: " . $result->type . ", id: " . $result->id . "}");
- return false;
- } else {
- return true;
- }
- });
- return new JSONResponse($results);
- }
- }
|