Simplify example
This commit is contained in:
@@ -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()]),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user