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.

Similar posts

Comments

makaroni4 commented 7 months ago

E302c3320cd14b02cbe237b479d7f884?size=52

:astonished:

You use this gem in production? How did you find it?

releu commented 7 months ago

757fb0d5ec7560b6f25f5bd98eadc020?size=52

lol :)

agentcooper
makaroni4
releu