Skip to content

fix(cli): --rank swallowed as a search term (zero-match bug)#15

Merged
exbuf merged 1 commit into
mainfrom
fix/rank-flag-swallowed
Jul 21, 2026
Merged

fix(cli): --rank swallowed as a search term (zero-match bug)#15
exbuf merged 1 commit into
mainfrom
fix/rank-flag-swallowed

Conversation

@exbuf

@exbuf exbuf commented Jul 21, 2026

Copy link
Copy Markdown
Owner

The bug (reported)

Searching bowling in a folder: 351 matches with "Sort by relevance" OFF, 0 matches with it ON. Ranking must only reorder — never change which matches are found.

Root cause

The CLI detected want_rank = "--rank" in args but never removed --rank from args (unlike --no-index, which does). So --rank leaked into the positional search terms — the query became bowling AND "--rank", which in AND mode matches nothing → 0 results. (In OR mode it silently polluted the query without dropping the count.) Confirmed via the query echo: Searching (OR, indexed) on [bowling --rank].

Fix

Strip --rank from args after detecting it, exactly like --no-index. Query echo is now on [bowling], and AND-mode with --rank finds the same matches as without.

Why it slipped through

Slice-1 tests exercised the Python API (search(rank=True)), never the CLI arg-parsing path. Added test_rank_flag_not_swallowed_as_search_term driving main() with --rank in both OR and AND mode — verified it fails without this fix and passes with it (the AND-mode return code directly encodes the 351→0 regression).

Verified

790 passed (incl. the new regression test); mypy clean; no version bump.

🤖 Generated with Claude Code

Reported: searching "bowling" found 351 matches with Sort by relevance OFF, but
0 with it ON. Root cause: the CLI detected `want_rank = "--rank" in args` but
never removed `--rank` from args (unlike --no-index), so it leaked into the
positional search terms. The query became `bowling AND "--rank"`, which in
AND mode matches nothing → 0 results. (In OR mode it silently polluted the query
without dropping the count.)

Fix: strip `--rank` from args after detecting it, exactly like --no-index.

The bug slipped through because slice-1 tests exercised the Python API
(search(rank=True)) but never the CLI arg-parsing path. Added a CLI regression
test (test_rank_flag_not_swallowed_as_search_term) that drives main() with
--rank in both OR and AND mode; verified it FAILS without this fix and PASSES
with it. No version bump.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Robert D. Schoening <bobschoening@gmail.com>
@exbuf
exbuf merged commit 4ede450 into main Jul 21, 2026
20 checks passed
@exbuf
exbuf deleted the fix/rank-flag-swallowed branch July 21, 2026 02:33
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