mirror of
https://github.com/koel/koel
synced 2024-12-25 12:03:06 +00:00
35 lines
907 B
PHP
35 lines
907 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\Search;
|
|
|
|
use App\Http\Controllers\API\Controller;
|
|
use App\Services\SearchService;
|
|
use Illuminate\Http\Request;
|
|
use InvalidArgumentException;
|
|
|
|
class ExcerptSearchController extends Controller
|
|
{
|
|
private SearchService $searchService;
|
|
|
|
public function __construct(SearchService $searchService)
|
|
{
|
|
$this->searchService = $searchService;
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
if (!$request->get('q')) {
|
|
throw new InvalidArgumentException('A search query is required.');
|
|
}
|
|
|
|
$count = (int) $request->get('count', SearchService::DEFAULT_EXCERPT_RESULT_COUNT);
|
|
|
|
if ($count < 0) {
|
|
throw new InvalidArgumentException('Invalid count parameter.');
|
|
}
|
|
|
|
return [
|
|
'results' => $this->searchService->excerptSearch($request->get('q'), $count),
|
|
];
|
|
}
|
|
}
|