3
0

Simplify example

This commit is contained in:
brabli
2026-05-08 11:18:50 +01:00
parent 90e23eb13e
commit e145892e87
+3 -6
View File
@@ -61,21 +61,18 @@ class Company implements SearchableInterface
Query the index from a controller and resolve each hit to a URL:
```php
#[Route('/search', name: 'app_search', methods: ['GET'])]
#[Route('/search', name: 'app_search')]
public function search(Request $request, SearchIndexRepository $repo): Response
{
$routes = [Company::class => 'app_company_show'];
$rows = $repo->findAllPagination($request->query->get('q', ''))->getResult();
$results = [];
foreach ($rows as [$index]) {
$route = $routes[$index->getEntityClass()] ?? null;
if ($route === null) {
continue;
}
$results[] = [
'title' => $index->getTitle(),
'url' => $this->generateUrl($route, ['id' => $index->getEntityId()]),
'url' => $this->generateUrl($routes[$index->getEntityClass()], ['id' => $index->getEntityId()]),
];
}