-
Notifications
You must be signed in to change notification settings - Fork 30
Quick Start
Tomas Norkūnas edited this page Mar 6, 2024
·
6 revisions
The SearchService
is your entry point for any operation with the Meilisearch engine:
- Index data
- Search
- Clear data
Symfony ships with a lighter container, where only core services are registered. If your controller will be responsible for search-related tasks, you can inject the SearchService
into the constructor by type-hinting the SearchService
interface. Symfony will take care of instantiating the right implementation for you.
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Meilisearch\Bundle\SearchService;
final class ExampleController extends AbstractController
{
public function __construct(
private readonly SearchService $searchService,
) {
}
}
You can also inject it directly into the function you'll need:
#[Route('/search')]
public function search(SearchService $searchService): Response
{
$hits = $searchService->search($this->getDoctrine()->getManager(), MyEntity::class, 'searched term'));
}