Skip to content

Match substrings fuzzily#6408

Merged
snejus merged 4 commits intomasterfrom
match-substrings-fuzzily
Mar 3, 2026
Merged

Match substrings fuzzily#6408
snejus merged 4 commits intomasterfrom
match-substrings-fuzzily

Conversation

@snejus
Copy link
Member

@snejus snejus commented Mar 3, 2026

Fixes #2043
Fixes #5638

Improve the fuzzy plugin in two ways:

  1. Make short fuzzy queries behave more like substring matching.
  2. Force fuzzy-prefixed queries to use slow evaluation so fuzzy logic is always applied.

Problem

Fuzzy prefix queries (for example ~foo or custom prefixes like %%foo) could take a fast DB query path on normal fields, which bypassed fuzzy semantics and produced broad/
unrelated matches #5638.

Also, when the query pattern was shorter than the field value, fuzzy matching was too strict for substring-style use cases #2043.

Thanks to @carreter for this in #5140. Opened a new PR since I did not have permissions to push to their fork.

Supersedes #5140.

@snejus snejus requested a review from a team as a code owner March 3, 2026 12:58
@snejus snejus mentioned this pull request Mar 3, 2026
3 tasks
@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.37%. Comparing base (bb08923) to head (48763ee).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6408      +/-   ##
==========================================
+ Coverage   69.33%   69.37%   +0.04%     
==========================================
  Files         141      141              
  Lines       18794    18801       +7     
  Branches     3061     3063       +2     
==========================================
+ Hits        13031    13044      +13     
+ Misses       5118     5111       -7     
- Partials      645      646       +1     
Files with missing lines Coverage Δ
beetsplug/fuzzy.py 96.15% <100.00%> (+32.99%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

PR make fuzzy plugin better when query shorter than field, so user can do substring-ish fuzzy search (help for noisy titles like YouTube). Also add changelog note for Unreleased.

Changes:

  • Scale fuzzy threshold by max possible ratio when len(pattern) < len(val).
  • Use quick_ratio() as cheap gate before ratio() calc.
  • Add changelog entry for fuzzy matching improvement.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/changelog.rst Add Unreleased note for fuzzy plugin behavior change.
beetsplug/fuzzy.py Adjust fuzzy matching logic to behave better for shorter queries.

@snejus snejus force-pushed the match-substrings-fuzzily branch from feece21 to 64d2a56 Compare March 3, 2026 13:57
@snejus snejus force-pushed the match-substrings-fuzzily branch from 64d2a56 to 48763ee Compare March 3, 2026 14:05
@snejus snejus merged commit 842354e into master Mar 3, 2026
20 checks passed
@snejus snejus deleted the match-substrings-fuzzily branch March 3, 2026 14:23
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.

Fuzzy Search Plugin not returning sensible results. fuzzy: Match substrings fuzzily

3 participants