Searching with SearchFilter
Searching with SearchFilter
~14 Min. Lesezeit Zuletzt aktualisiert am August 8, 2026
So far, only paging through ALL projects page by page is possible – the SearchFilter adds TARGETED searching by field value, AGAIN WITHOUT any custom query code.
Applying SearchFilter
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
#[ApiResource(
normalizationContext: ['groups' => ['project:read']],
denormalizationContext: ['groups' => ['project:write']]
)]
#[ApiFilter(SearchFilter::class, properties: [
'name' => 'partial',
'description' => 'partial',
])]
#[ORM\Entity(repositoryClass: ProjectRepository::class)]
class Project
{
// ... unchanged
}#[ApiFilter] is a FURTHER attribute ALONGSIDE #[ApiResource] – the properties array determines WHICH fields are searchable and WITH which comparison strategy.
partial vs. exact
| Strategy | Behavior |
|---|---|
partial | SQL LIKE %value% – finds substrings, case is usually ignored |
exact | SQL = value – ONLY an exact match |
start | SQL LIKE value% – match ONLY at the start |
end | SQL LIKE %value – match ONLY at the end |
Testing the search
curl -k 'https://localhost/api/projects?name=Relaunch'{
"hydra:member": [
{"id": 1, "name": "Website Relaunch", "...": "..."}
],
"hydra:totalItems": 1
}The name query parameter MATCHES the property name from the properties array – name=Relaunch ALSO finds "Website Relaunch", since partial is configured.
Combining multiple search criteria
curl -k 'https://localhost/api/projects?name=Website&description=Redesign'MULTIPLE query parameters get combined with AND AUTOMATICALLY – ONLY projects that meet BOTH criteria AT ONCE appear in the result.
Tipp: SearchFilter AUTOMATICALLY appears in Swagger UI (chapter 6) as its own query parameter fields – a CONVENIENT way to try out filters INTERACTIVELY without typing curl commands by hand.