fix/query: preserve fields in parenthesized atoms - #1078
Merged
Conversation
Users reasonably expect wrapping a field query in parentheses to preserve its semantics, but the parser's regex/grouping ambiguity caused no-space forms like (sym:foo) to be treated as plain content text. Recognize field-looking parenthesized atoms as grouping so generated and hand-written field queries behave consistently while leaving bare regex grouping such as (foo) and (foo|bar) alone. Amp-Thread-ID: https://ampcode.com/threads/T-019ef884-75bf-736d-b3b7-e19a7855d882 Co-authored-by: Amp <amp@ampcode.com>
Parenthesized query syntax should not revert to content matching simply because callers add another grouping layer. Skip grouping and negation markers before checking field prefixes so nested and negated forms follow the same parser path. Amp-Thread-ID: https://ampcode.com/threads/T-01a03d0c-8a63-778e-8329-58af0957888e
burmudar
approved these changes
Aug 26, 2026
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.
Fixes #1074.
No-space parenthesized field expressions currently take the regular-expression/text path, so
(sym:foo)searches content for the literal textsym:foo; adding whitespace after the opening parenthesis makes the same expression a grouped symbol query.This updates the tokenizer heuristic so parenthesized expressions that begin with known field syntax enter the existing grouping parser. It applies consistently to nested and negated forms such as
((sym:foo)),(-sym:foo), and-(file:test). Bare parenthesized regular expressions such as(foo),(foo|bar), and(foo)(bar)retain their existing behavior to avoid a broader compatibility change. The query syntax and parser design documentation now describe this distinction.