-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathSearchController.php
More file actions
58 lines (49 loc) · 1.63 KB
/
Copy pathSearchController.php
File metadata and controls
58 lines (49 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
/*
* UserFrosting Learn (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/Learn
* @copyright Copyright (c) 2025 Alexander Weissman & Louis Charette
* @license https://github.com/userfrosting/Learn/blob/main/LICENSE.md (MIT License)
*/
namespace UserFrosting\Learn\Controller;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use UserFrosting\Learn\Search\SearchSprunje;
/**
* Controller for the documentation search API.
*/
class SearchController
{
public function __construct(
protected SearchSprunje $sprunje,
) {
}
/**
* Search documentation pages.
* Request type: GET.
*
* Query parameters:
* - q: Search query (required, min length from config)
* - page: Page number for pagination (optional, default 1)
* - size: Number of results per page (optional, default from config, null means all results)
* - version: Documentation version (optional, defaults to latest)
*
* @param Request $request
* @param Response $response
*/
public function search(Request $request, Response $response): Response
{
$params = $request->getQueryParams();
$this->sprunje
->setQuery($params['q'] ?? '')
->setVersion($params['version'] ?? null)
->setPage((int) ($params['page'] ?? 1));
// Only set size if explicitly provided
if (isset($params['size'])) {
$this->sprunje->setSize((int) $params['size']);
}
return $this->sprunje->toResponse($response);
}
}