Skip to content

Commit

Permalink
Assert the query string parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jul 8, 2024
1 parent c9561c3 commit 61898fc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
use Webmozart\Assert\Assert;

final class SearchController
{
Expand All @@ -39,19 +40,22 @@ public function __construct(

public function search(Request $request, SearchFormBuilderInterface $searchFormBuilder, FilterBuilderInterface $filterBuilder): Response
{
$q = $request->query->get('q');
Assert::nullOrString($q);

$index = $this->indexRegistry->get($this->searchIndex);

$items = [];

$searchResult = $this->client->index($this->indexNameResolver->resolve($index))->search($request->query->getString('q'), [
$searchResult = $this->client->index($this->indexNameResolver->resolve($index))->search($q, [
'facets' => $this->getFacets($index->document),
'filter' => $filterBuilder->build($request),
]);

$searchForm = $searchFormBuilder->build($searchResult);
$searchForm->handleRequest($request);

dump($searchResult);
//dump($searchResult);

/** @var array{entityClass: class-string<IndexableInterface>, entityId: mixed} $hit */
foreach ($searchResult->getHits() as $hit) {
Expand Down

0 comments on commit 61898fc

Please sign in to comment.