Search code examples
mysqlruby-on-railslevenshtein-distance

Can I use ActiveRecord to find rows based on nearest-match (levenshtein distance)


I have a table of strings in my database. I select one of them, A.

How I can search the rest of the table to find the string most similar to A?


Solution

  • I think you are looking for the levenstein distance. The levenstein distance between 2 string, is how much adding/deleting/modifying char is needed to make the string equals.

    Here's an implementation in Ruby