mirror of
https://github.com/beetbox/beets.git
synced 2026-02-08 08:25:23 +01:00
Merge 655b0bdc77 into cdfb813910
This commit is contained in:
commit
ac967fc167
1 changed files with 13 additions and 1 deletions
|
|
@ -29,7 +29,19 @@ class FuzzyQuery(StringFieldQuery[str]):
|
|||
val = val.lower()
|
||||
query_matcher = difflib.SequenceMatcher(None, pattern, val)
|
||||
threshold = config["fuzzy"]["threshold"].as_number()
|
||||
return query_matcher.quick_ratio() >= threshold
|
||||
# Adjust match threshold for the case that the pattern is shorter
|
||||
# than the value being matched. This allows the pattern to match
|
||||
# substrings of the value, not just the entire value.
|
||||
if len(pattern) < len(val):
|
||||
max_possible_ratio = 2 * len(pattern) / (len(pattern) + len(val))
|
||||
threshold *= max_possible_ratio
|
||||
|
||||
# If upper bound of the ratio meets threshold, then calculate
|
||||
# the actual ratio.
|
||||
if query_matcher.quick_ratio() >= threshold:
|
||||
return query_matcher.ratio() >= threshold
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class FuzzyPlugin(BeetsPlugin):
|
||||
|
|
|
|||
Loading…
Reference in a new issue