Module
Constants
No documentation available
No documentation available
Instance Methods
lib/did_you_mean/jaro_winkler.rb
View on GitHub
# File tmp/rubies/ruby-3.3.0/lib/did_you_mean/jaro_winkler.rb, line 68
def distance(str1, str2)
jaro_distance = Jaro.distance(str1, str2)
if jaro_distance > THRESHOLD
codepoints2 = str2.codepoints
prefix_bonus = 0
i = 0
str1.each_codepoint do |char1|
char1 == codepoints2[i] && i < 4 ? prefix_bonus += 1 : break
i += 1
end
jaro_distance + (prefix_bonus * WEIGHT * (1 - jaro_distance))
else
jaro_distance
end
end
No documentation available