10

I'm trying to implement a "Did you mean?" sort of function for a search.

I'm trying to do a query that uses the levenshtein function, which was written in ruby. I was wondering how I could use this function in a sqlite3 query. I was thinking it might be something like this:

@results = the_db.where('levenshtein(name, ?) <= 3', searchphrase)

But i'm not sure how to get it to work. Could someone help me out?

areke
  • 1,093
  • 1
  • 14
  • 23
  • http://stackoverflow.com/questions/11836462/using-levenshtein-distance-ratio-to-compare-2-records This helps? – Nishant Dec 18 '12 at 07:35

1 Answers1

5

Try the editdist3 function:

The editdist3 algorithm is a function that computes the minimum edit distance (a.k.a. the Levenshtein distance) between two input strings.

nickaknudson
  • 4,769
  • 2
  • 15
  • 16
  • 3
    [This](https://stackoverflow.com/a/49815419/1422096) is a HOWTO + ready-to-use example for both Windows and Linux. – Basj Apr 13 '18 at 11:05