Skip to content

Fix group precedence in TypesenseFilterExpressionConverter - #6741

Open
0xmisha wants to merge 1 commit into
spring-projects:mainfrom
0xmisha:fix-typesense-group-precedence
Open

Fix group precedence in TypesenseFilterExpressionConverter#6741
0xmisha wants to merge 1 commit into
spring-projects:mainfrom
0xmisha:fix-typesense-group-precedence

Conversation

@0xmisha

@0xmisha 0xmisha commented Aug 5, 2026

Copy link
Copy Markdown

The doGroup override in TypesenseFilterExpressionConverter converts a parenthesized filter group into content && content, duplicating the group body and dropping the parentheses that express grouping.

Because Typesense evaluates && and || with equal precedence from left to right, a filter such as

city == "Sofia" AND (year >= 2020 OR country == "BG")

is currently emitted as

metadata.city: "Sofia" && metadata.year: >= 2020 || metadata.country: "BG" && metadata.year: >= 2020 || metadata.country: "BG"

This allows documents with country == "BG" to match regardless of the city condition.

Replace the doGroup override with the conventional doStartGroup and doEndGroup hooks that wrap the group content in parentheses.

Testing

Added testGroupAsRightOperand covering a grouped OR expression used as the right-hand operand of an AND.
The expected filter preserves the original grouping:

metadata.city: "Sofia" && (metadata.year: >= 2020 || metadata.country: "BG")

Signed-off-by: Fedotov Mikhail <mixxxaile@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants