Finding similar names with Levenshtein distance by releu
The Levenshtein distance is a string metric for measuring the difference between two sequences.
http://en.wikipedia.org/wiki/Levenshtein_distance
For #ruby you can use #gem levenshtein-ffi and do something like this:
class Organization < ActiveRecord::Base
def self.find_similar(name)
all.find_all do |org|
Levenshtein.distance(name, org.name) < [name.size / 3.0, 3].max
end
end
end
And help your users to prevent mistakes of typing.
Comments
makaroni4 commented 7 months ago
You use this gem in production? How did you find it?
releu commented 7 months ago
@divineforest recommended the method, and then I google :)
agentcooper commented 7 months ago
https://twitter.com/garybernhardt/status/256181800928411651
releu commented 7 months ago
lol :)