Skip to content

fix(ck-engine): parse lexical queries leniently instead of erroring on tantivy syntax#166

Open
ak2k wants to merge 1 commit into
BeaconBay:mainfrom
ak2k:ck-lenient-query
Open

fix(ck-engine): parse lexical queries leniently instead of erroring on tantivy syntax#166
ak2k wants to merge 1 commit into
BeaconBay:mainfrom
ak2k:ck-lenient-query

Conversation

@ak2k

@ak2k ak2k commented Jul 5, 2026

Copy link
Copy Markdown

ck is grep-shaped, so lexical (--lex) queries arrive as arbitrary strings — from shell one-liners, scripts, and AI agents — that were never meant to be tantivy query syntax. QueryParser::parse_query rejects the whole search when the input contains anything it can't fully interpret: an unbalanced quote, a stray field: colon, a bare AND/OR, a leading wildcard. The terms that could still match are discarded along with the syntax error, and callers are forced to sanitize queries before handing them over.

Switch lexical_search to QueryParser::parse_query_lenient: the interpretable terms are kept and the un-parseable fragments are dropped, with the parser's errors logged at debug level rather than propagated. A query that already parses cleanly yields the same query object, so its results and scores are unchanged (covered by an invariance test comparing strict and lenient parses); a query where every fragment errors degrades to normal empty results instead of a hard failure.

If you'd rather keep strict parsing as the default, this could sit behind a flag instead — happy to rework it that way.

…n tantivy syntax

ck is grep-shaped, so lexical (--lex) queries arrive as arbitrary strings — from
shell one-liners, scripts, and AI agents — that were never meant to be tantivy
query syntax. QueryParser::parse_query rejects the whole search when the input
contains anything it can't fully interpret: an unbalanced quote, a stray
`field:` colon, a bare AND/OR, a leading wildcard. The terms that could still
match are discarded along with the syntax error, and callers are forced to
sanitize queries before handing them over.

Switch lexical_search to QueryParser::parse_query_lenient: the interpretable
terms are kept and the un-parseable fragments are dropped, with the parser's
errors logged at debug level rather than propagated. A query that already parses
cleanly yields the same query object, so its results and scores are unchanged
(covered by an invariance test comparing strict and lenient parses); a query
where every fragment errors degrades to normal empty results instead of a hard
failure.
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.

1 participant