Is there a particular reason why the fuzzing methods return an `Option`?
mainrs opened this issue · 5 comments
It seems quite unintuitive. I am not familiar with fuzzing internals but from a user perspective, it makes more sense to me that the methods would always return a score. A score of 0 would just mean that the two terms do not match at all.
Especially because the other two tests before return Some(0)
. Maybe it's a relict from the earlier days of the library?
I just think it's easier to work with if it simply returns a usize. And if it's zero, there were no matches. Doesn't matter if the input was ASCII and the pattern was a Chinese character or empty. The current behaviour just doesn't seem to be consistent in all cases.
@SirWindfield The fuzzy matching algorithm has penalties. The score might be 0
or even negative.
As for these cases:
assert_eq!(Some(0), matcher.fuzzy_match("abcdefaghi", ""));
assert_eq!(None, matcher.fuzzy_match("", "a"));
Note that the semantic of a fuzzy matching is match(choice, pattern)
, so
- for
match("abcdefaghi", "")
, The pattern""
could be "found" in choice, thus returningSome
with some score. - for
match("", "a")
The pattern"a"
could not be found in choice""
, thus returningNone
thanks for taking your time and explaining the reason behind the return type.