fix(autotag): "featuring" pattern in string_dist matches mid-word "ft"#6843
Open
chuenchen309 wants to merge 3 commits into
Open
fix(autotag): "featuring" pattern in string_dist matches mid-word "ft"#6843chuenchen309 wants to merge 3 commits into
chuenchen309 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6843 +/- ##
==========================================
- Coverage 75.60% 75.59% -0.02%
==========================================
Files 163 163
Lines 21299 21299
Branches 3358 3358
==========================================
- Hits 16103 16100 -3
- Misses 4406 4408 +2
- Partials 790 791 +1
🚀 New features to boost your workflow:
|
snejus
requested changes
Jul 16, 2026
Author
|
Applied — added the trailing |
snejus
enabled auto-merge
July 16, 2026 12:13
SD_PATTERNS' featuring/feat/ft regex has no word boundary before the alternation, so it matches "ft" embedded in ordinary words like "draft", "left", "gift", "craft" and treats everything after it as a low-weight suffix. "Draft Beer" vs. "Draft Whiskey" scores 0.05 (near-identical) instead of correctly registering as very different.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Apply reviewer suggestion (@snejus): add a trailing \b after the (featuring|feat|ft) alternation so the boundary is explicit on both sides, matching the leading \b. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
snejus
force-pushed
the
fix/distance-featuring-pattern-mid-word-match
branch
from
July 16, 2026 12:14
83e39c0 to
f0bb497
Compare
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.
Bug
SD_PATTERNSinbeets/autotag/distance.pyhas this entry:The
ftalternative has no word boundary before it, so it matchesftembedded inside any ordinary word followed by a space/period/colon —draft,left,gift,craft,soft,swift, etc. — and treats everything after the match as a low-weight "featuring artist" suffix (weight0.1), effectively deleting it from the comparison.Confirmed through the actual matching pipeline (
track_distance) too: "Draft Beer" vs. "Draft Whiskey" scores almost as close as an exact match, while a genuinely unrelated title correctly scores much higher.string_dist/add_stringbacks nearly every fuzzy field comparison used duringbeet import(title, artist, album, label, catalognum, ...), so this silently degrades match quality for any title/artist containing one of these words.Fix
Add a word boundary before the alternation:
Verified this doesn't regress the intended "real" cases (
"Song feat. Artist","[feat: Artist]","(ft. Artist)"— all still match, since they're preceded by whitespace/bracket/string-start, which are real boundaries) while excluding all the false-positive mid-word cases above.Testing
Added
test_featuring_pattern_does_not_match_mid_word(parametrized over draft/left/gift/craft) totest/autotag/test_distance.py, assertingstring_dist(...) > 0.3for these pairs (previously ~0.04-0.07). Verified red onmaster(git stashthe source fix — all 4 cases fail with the near-zero distances shown above), green after. Fulltest/autotag/test_distance.py(58 passed) and the broadertest/autotag/+test/util/+test/autotag/test_match.py+test/test_importer.pysuites (352 + 142 passed, no regressions) all pass.ruff check/ruff format --check/mypyclean.Added a changelog entry per
CONTRIBUTING.rst's reminder.Duplicate-work check
Searched open PRs for
distance.py/"featuring" — found #6681 (Source class refactor) also touchesdistance.py, but its diff doesn't touchSD_PATTERNSor this area at all. No overlap.This PR was drafted with AI assistance (Claude); I independently reproduced the bug against the real, unmodified module (including through the full
track_distancematching pipeline) and verified the fix. I reviewed the change and take responsibility for it.