【发布时间】:2021-03-31 13:15:49
【问题描述】:
我有如下所列的 SQL 表设计
*-----------------------------------------
| id | title |
| -- | -----------------------------------|
| 1 | This is nice pen looking good |
| 2 | This is nice pen looking elegent |
| 3 | This is nice pen looking great |
| 4 | This is nice pen looking best. |
------------------------------------------
示例查询:Select * from table where title LIKE '%looking%'
当我尝试使用 (like query) 或使用 (Regular Expressions) 例如示例查询来搜索词 "looking" 时,我获得下面提到的完整字符串结果
结果
*------------------------------------
| title |
| -----------------------------------|
| This is nice pen looking good |
| This is nice pen looking elegent |
| This is nice pen looking great |
| This is nice pen looking best. |
-------------------------------------
我想要什么?
我想要预测性搜索词(不是完整的字符串)
我如何通过使用 SQL 搜索单词(查找)来获得以下提到的结果。
*-------------------
| title |
| ------------------|
| looking good |
| looking elegent |
| looking great |
| looking best. |
--------------------
请建议我如何编写查询以获得这些类型的结果? 谢谢
【问题讨论】:
-
请解释一下你所说的“预测性搜索词”是什么意思。
-
表示当我尝试搜索单词“looking”时,我想要精确匹配单词的结果和搜索单词的下一个单词。搜索词:“寻找”结果我想要“看起来不错”“看起来优雅”“看起来很棒”等
-
一个有趣的问题,但错误的工具集。 Mysql 是一个数据库,而不是一个文本分析工具。它没有词的概念。你显然可以组合一组字符串函数,并在 mysql 中实现你想要的紧密代理,但性能会很糟糕。
标签: mysql sql search full-text-search exact-match