Skip to content

feat(doctrine): add locale-constrained search and order filters - #91

Merged
paullla merged 5 commits into
Locastic:masterfrom
paullla:feat/translation-filters
Nov 17, 2026
Merged

paullla merged 5 commits into
Locastic:masterfrom
paullla:feat/translation-filters

Conversation

@paullla

@paullla paullla commented Nov 17, 2026

Copy link
Copy Markdown
Member
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Issues fixes #47, fixes #57, relates to #24
License MIT

Problem

Translated values live on the translation entity, so a core SearchFilter or OrderFilter declared on translations.title matches and sorts against every locale at once. A client that requests ?locale=de cannot filter or order the collection by the German value it actually sees. This is the most requested feature in the tracker (#24, #47, #57).

Changes

  • Add TranslationSearchFilter and TranslationOrderFilter (both @experimental) in Doctrine\Orm\Filter. They take the translation entity's fields by their bare name (title, not translations.title) and constrain a dedicated left join to the locale resolved from the request (?locale=, then Accept-Language, per locale_resolution).
  • The two filters share one join, and the join is never selected. The eager-loading extension from feat(doctrine): eagerly load translations of translatable resources #88 ignores conditioned joins, so the hydrated translations collection stays complete (fallback reads and ?groups[]=translations are not affected).
  • TranslationSearchFilter mirrors the strategies of the core SearchFilter (exact, partial, start, end, word_start, each with an optional i prefix) and accepts multiple values (?title[]=a&title[]=b).
  • TranslationOrderFilter keeps resources that have no translation in the current locale (left join, database null ordering). A direction in properties is the default when the query parameter gives none.
  • Both filters match the resolved locale only. Fallback-locale values are not considered, which the README states explicitly.
  • Both are registered as abstract parents under the class name (what #[ApiFilter] builds child definitions from), and only when api-platform/doctrine-orm is installed.
  • README: new "Filter and order by translated fields" section, which replaces the filtering entry in Limitations. CHANGELOG entry under Unreleased. One context7 rule that recommends these filters over a core SearchFilter on translations.field.

A SearchFilter or OrderFilter declared on `translations.field` matches
and sorts against every locale at once, so filtering or ordering a
collection by the value the client actually sees has not been possible
(Locastic#24, Locastic#47, Locastic#57).

TranslationSearchFilter and TranslationOrderFilter take the translation
entity's fields by their bare name and constrain a dedicated left join
to the locale resolved from the request. The join is shared between the
two filters, is never selected (the eager-loading extension ignores
conditioned joins, keeping hydrated collections complete), and ordering
keeps resources without a translation in the current locale. The search
strategies mirror the core SearchFilter. Both filters are registered as
abstract parents under the class name, which is what the ApiFilter
attribute builds child definitions from, and only when
api-platform/doctrine-orm is installed.
README usage section (replacing the filtering entry in Limitations,
which the filters resolve), CHANGELOG entry, and a context7 rule so
agent-facing docs recommend the locale-constrained filters over a core
SearchFilter on translations.field.
The partial and word_start cases searched for 'cat' and expected a match
on 'Catalog DE', which only holds where LIKE ignores ASCII case (sqlite).
Store the seeded title in lower case and search in the stored case, so
the case-sensitive strategies are asserted with data that is true on
case-sensitive databases too. Checked against PostgreSQL 16.
@paullla paullla added the enhancement New feature or request label Nov 17, 2026
A searched value containing % or _ was passed to LIKE as is, so
?title=50% also matched '500 offers'. Escape both (and the escape
character itself) and add an ESCAPE clause to every LIKE strategy, as
the parameter-based core search filters do.
Which index serves which search strategy, why the leading-wildcard and
case-insensitive strategies need a database-specific text index, and
that ordering by a translated field sorts the whole filtered collection.
@paullla
paullla merged commit 6686dd7 into Locastic:master Nov 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter on current locale translations OrderFilter on translated fields and a certain locale

1 participant