Repository navigation
feat(doctrine): add locale-constrained search and order filters - #91
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Translated values live on the translation entity, so a core
SearchFilterorOrderFilterdeclared ontranslations.titlematches and sorts against every locale at once. A client that requests?locale=decannot 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
TranslationSearchFilterandTranslationOrderFilter(both@experimental) inDoctrine\Orm\Filter. They take the translation entity's fields by their bare name (title, nottranslations.title) and constrain a dedicated left join to the locale resolved from the request (?locale=, thenAccept-Language, perlocale_resolution).translationscollection stays complete (fallback reads and?groups[]=translationsare not affected).TranslationSearchFiltermirrors the strategies of the coreSearchFilter(exact,partial,start,end,word_start, each with an optionaliprefix) and accepts multiple values (?title[]=a&title[]=b).TranslationOrderFilterkeeps resources that have no translation in the current locale (left join, database null ordering). A direction inpropertiesis the default when the query parameter gives none.#[ApiFilter]builds child definitions from), and only whenapi-platform/doctrine-ormis installed.SearchFilterontranslations.field.