Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m24s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m26s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m31s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
35 lines
1.4 KiB
PHP
35 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\Qm;
|
|
|
|
use App\Models\User;
|
|
use App\Search\GlobalSearch;
|
|
|
|
/** Suchquelle für die globale Suche: QM-Dokumente inkl. Volltext */
|
|
class QmSearch
|
|
{
|
|
public function __construct(private readonly Search $search, private readonly Presenter $presenter, private readonly QmAccess $access) {}
|
|
|
|
/**
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
public function __invoke(User $user, string $search, int $limit): array
|
|
{
|
|
if (! $this->access->allows($user)) {
|
|
return [];
|
|
}
|
|
|
|
return $this->search->run($search, $user)->take($limit)->map(function (array $hit) use ($search) {
|
|
$entry = $this->presenter->entry($hit['entry']);
|
|
|
|
return [
|
|
'title' => $hit['entry']->title,
|
|
'url' => $entry['open_url'] ?? $this->presenter->folderLabel($hit['entry']->folder_id)['url'],
|
|
'external' => ($entry['open_kind'] ?? null) === 'download' || ($entry['open_kind'] ?? null) === 'link',
|
|
'excerpt' => $hit['snippet'] ?? GlobalSearch::excerpt($hit['entry']->description, $search),
|
|
'meta' => collect([$this->presenter->folderLabel($hit['entry']->folder_id)['path'], $hit['entry']->version ? 'Version '.$hit['entry']->version : null])->filter()->implode(' · '),
|
|
'file' => $entry['extension'] ?? null,
|
|
];
|
|
})->values()->all();
|
|
}
|
|
}
|