Skip to content

Commit

Permalink
Merge pull request #66 from soee/fixDependencyInjectionForElasticRepo…
Browse files Browse the repository at this point in the history
…sitory

[BUGFIX] Use DI when instantiating ElasticRepository inside SearchCon…
  • Loading branch information
linawolf authored Feb 15, 2024
2 parents d82444d + 04eb240 commit 99cf6a2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class SearchController extends AbstractController
{
public function __construct(private readonly ElasticRepository $elasticRepository)
{
}


/**
* @return Response
*/
Expand All @@ -32,13 +37,12 @@ public function search(Request $request): Response
if ($request->query->get('q', '') === '') {
return $this->redirectToRoute('index');
}
$elasticRepository = new ElasticRepository();
$searchDemand = SearchDemand::createFromRequest($request);

return $this->render('search/search.html.twig', [
'q' => $searchDemand->getQuery(),
'filters' => $request->get('filters', []),
'results' => $elasticRepository->findByQuery($searchDemand),
'results' => $this->elasticRepository->findByQuery($searchDemand),
]);
}

Expand All @@ -49,10 +53,9 @@ public function search(Request $request): Response
#[Route(path: '/suggest', name: 'suggest')]
public function suggest(Request $request): Response
{
$elasticRepository = new ElasticRepository();
$searchDemand = SearchDemand::createFromRequest($request);

$results = $elasticRepository->suggest($searchDemand);
$results = $this->elasticRepository->suggest($searchDemand);
$suggestions = [];
foreach ($results['results'] as $result) {
$hit = $result->getData();
Expand Down

0 comments on commit 99cf6a2

Please sign in to comment.