如何在字段中实现模糊搜索单词?
我有一些非常基本的初学者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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论