如何在 sqlite where 子句中使用 Levenshtein 距离函数? [英] How do I use a Levenshtein distance function in a sqlite where clause?

查看:63
本文介绍了如何在 sqlite where 子句中使用 Levenshtein 距离函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施您是说吗?"一种搜索功能.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆