fix(cli): --rank swallowed as a search term (zero-match bug)#15
Merged
Conversation
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>
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.
The bug (reported)
Searching
bowlingin 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 argsbut never removed--rankfromargs(unlike--no-index, which does). So--rankleaked into the positional search terms — the query becamebowling 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
--rankfromargsafter detecting it, exactly like--no-index. Query echo is nowon [bowling], and AND-mode with--rankfinds 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. Addedtest_rank_flag_not_swallowed_as_search_termdrivingmain()with--rankin 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