How do I use a Levenshtein distance function in a sqlite where clause?

五迷三道 提交于 2019-12-18 12:36:09

问题


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?


回答1:


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.

  • http://www.sqlite.org/spellfix1.html


来源:https://stackoverflow.com/questions/13928320/how-do-i-use-a-levenshtein-distance-function-in-a-sqlite-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!