fix(score): rank exact filename stem match above fuzzy filename (#722) - #728
fix(score): rank exact filename stem match above fuzzy filename (#722)#728gustav-fff wants to merge 2 commits into
Conversation
…me (#722) `is_exact_filename` required the needle to equal the full filename (including extension), so `lsp` vs `lsp.lua` fell through to the `fuzzy_filename` branch capped at ~16% and only outranked `lsp/typos_lsp.lua` by a couple of points — any frecency or git bonus on the longer file overturned the order. Add an `is_exact_stem` check: needle equals the filename portion before the LAST dot (`lsp` ↔ `lsp.lua`, but NOT `foo.bar` ↔ `foo.bar.lua`). Awards a 30% base_score bonus — clearly above fuzzy_filename (~16%), below exact_filename (40%) — so the intended file wins by a comfortable margin without stealing rank from truly exact filename hits. Closes #722
dmtrKovalenko
left a comment
There was a problem hiding this comment.
@gustav-fff this is very inefficient, find a way to make this good enough so i can pick it up
Length-gate the exact-filename and exact-stem checks by fname_len before touching the arena. Both variants are mutually exclusive by length, so the filename is now read at most once per candidate (previously the stem branch redundantly rewrote fname_buf even after exact_filename already did) and only when the length pre-check makes either plausible.
|
[triage-bot] DIRECTED: pushed 9d8f63f. Consolidated exact-filename / exact-stem into one branch with cheap length gates first:
Net effect: on non- Tests: Let me know if you want a different rank position (currently 30% between fuzzy_filename ~16% and exact_filename 40%) or a stricter stem definition (e.g. reject dot-prefixed filenames). Honk-Honk 🪿 |
|
[triage-bot] DIRECTED: pushed 9d8f63f — length-gate the exact-filename and exact-stem checks before touching the arena. Before: hot loop did up to TWO After: single fused check. Cheap length-based pre-check first — exact needs
All 125 If you want it more aggressive (e.g. inline the ascii-lowercase compare from the arena chunks directly without materializing at all), say the word and I'll do that pass — it's a bigger change touching Honk-Honk 🪿 |
Closes #722
Root cause
crates/fff-core/src/score.rs:757—is_exact_filenamerequiresmain_needle_len == fname_lenand a case-insensitive equality against the ENTIRE filename (including extension). A query that exactly matches the filename stem (e.g.lsp↔lsp.lua) falls through into thefuzzy_filenamebranch capped at ~16% ofbase_score.lsp.lua(2-char subsequence in an 7-char filename) andlsp/typos_lsp.lua(2-char subsequence in a 13-char filename) both land there, differ by only 2 points, and any frecency/git bonus on the longer file flips the order.Fix
crates/fff-core/src/score.rs— addis_exact_stem:truewhen the needle equals the filename's stem (bytes before the LAST dot) and there is no additional dot beyond that. Awards a 30%base_scorebonus, positioned betweenfuzzy_filename(~16%) andexact_filename(40%). Adds a newmatch_type = "exact_stem"and includes it inexact_match.Steps to reproduce
Add this unit test to
crates/fff-core/src/score.rsinsidemod filename_bonus_tests(uses the existingmake_files/searchhelpers already in that module) and run againstorigin/main:Run:
cargo test --lib --manifest-path crates/fff-core/Cargo.toml issue_722_repro -- --nocaptureExpected (bug):
lsp.lua total=56 bonus=8 type=fuzzy_filenameandlsp/typos_lsp.lua total=54 bonus=6 type=fuzzy_filename. Both files score as generic fuzzy matches; the 2-point gap is trivially overturned by any frecency/git bonus onlsp/typos_lsp.lua, causing it to rank first as the reporter observed in the screenshot.How verified
test_exact_stem_beats_fuzzy_filenameassertslsp.luaranks first withmatch_type == "exact_stem".cargo test --libincrates/fff-core: 125 passed, 0 failed.make test— all Rust + Lua + bun tests pass (pre-existingtscenv issue intest-nodeunrelated to change).Post-fix output for the repro:
Automated triage via Gustav. Honk-Honk 🪿