如何在 sqlite where 子句中使用 Levenshtein 距离函数? [英] How do I use a Levenshtein distance function in a sqlite where clause?
问题描述
我正在尝试实施您是说吗?"一种搜索功能.
I'm trying to implement a "Did you mean?" sort of function for a search.
我正在尝试使用用 ruby 编写的 levenshtein 函数进行查询.我想知道如何在 sqlite3 查询中使用这个函数.我在想它可能是这样的:
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?
推荐答案
试试 editdist3
功能:
editdist3 算法是一个计算最小编辑的函数两个输入字符串之间的距离(又名 Levenshtein 距离).
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
这篇关于如何在 sqlite where 子句中使用 Levenshtein 距离函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!