如何在字段中实现模糊搜索单词?

发布于 2025-01-31 09:50:00 字数 551 浏览 4 评论 0原文

我有一些非常基本的初学者SQL知识。我遇到了Soundex并喜欢并试图在我的代码中实现它们。

在我的数据库中,我有一个名称列,其中包含一个人的所有可用名称(第一,第二,第三等)。

到目前为止,它看起来像这样:

SELECT names, date_of_birth, information
FROM person_list as p
WHERE ((SOUNDEX(%s) = SOUNDEX(names)) OR (names LIKE CONCAT('%', %s, '%')))

仅当输入是全名时,这才有效。例如,说我和“约翰·史密斯”(John Smith)有一个领域,如果我搜索了“乔恩·史密斯(Jon Smyth)”,这会很好。

但是,如果我只想搜索“ smyth”,就不会出现。而且,如果有一个包含“约翰·托马斯·史密斯(John Thomas Smith)”的领域,我将无法搜索“乔恩·史密斯(Jon Smyth)”,并让那个领域出现。

如何模糊搜索字段中的单词或多个单词? (我还愿意使用我更舒服的Python找到解决方案!)

谢谢!

I have some very basic beginner SQL knowledge. I've come across SOUNDEX and LIKE and have tried to implement them in my code.

In my database, I have a names column that contains all available names for a person (first, second, third, etc).

So far it looks like this:

SELECT names, date_of_birth, information
FROM person_list as p
WHERE ((SOUNDEX(%s) = SOUNDEX(names)) OR (names LIKE CONCAT('%', %s, '%')))

This only works if the input is the full name. For example, say I had a field with 'John Smith', if I searched 'Jon Smyth', this would work fine.

However, if I wanted to only search 'Smyth', nothing would come up. And if there was a field containing 'John Thomas Smith' I wouldn't be able to search for 'Jon Smyth' and have that field come up.

How do I fuzzy search for a word or multiple words within a field? (I am also open to finding a solution using Python which I am more comfortable with!)

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文