Skip to content

fix/query: preserve fields in parenthesized atoms - #1078

Merged
keegancsmith merged 2 commits into
mainfrom
k/fix-parenthesized-fields
Aug 26, 2026
Merged

fix/query: preserve fields in parenthesized atoms#1078
keegancsmith merged 2 commits into
mainfrom
k/fix-parenthesized-fields

Conversation

@keegancsmith

@keegancsmith keegancsmith commented Jun 24, 2026

Copy link
Copy Markdown
Member

Fixes #1074.

No-space parenthesized field expressions currently take the regular-expression/text path, so (sym:foo) searches content for the literal text sym: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.

keegancsmith and others added 2 commits June 24, 2026 10:16
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
@keegancsmith
keegancsmith marked this pull request as ready for review August 26, 2026 08:01
@keegancsmith
keegancsmith requested review from a team and burmudar August 26, 2026 08:28
@keegancsmith
keegancsmith merged commit c4a225a into main Aug 26, 2026
7 checks passed
@keegancsmith
keegancsmith deleted the k/fix-parenthesized-fields branch August 26, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Singular Keyword inside parentheses treated as regular string

2 participants