【问题标题】:Fulltext search against table row针对表格行的全文搜索
【发布时间】:2014-08-09 12:17:20
【问题描述】:

我试图在给定文本中突出显示最多 2 个单词。搜索关键字来自具有数百个可能匹配项和重要性信息的 mysql 表。

例如:“疯狂的狐狸跳过红牛”

可能匹配的mysql表“单词”:

keyword  importance
bird     0,2
fox      0,5
cow      0,1
red      0,4

查询应该返回 fox 和 red。

类似这样的:

SELECT keyword
from db.words
WHERE keyword matches ('The cracy fox jumps over the red cow')
ORDER BY importance
LIMIT 2

感谢您提供有关如何实现此目的的任何提示!

【问题讨论】:

    标签: php mysql sql full-text-search


    【解决方案1】:

    如果你不介意输出重要性:

    SELECT keyword, match(keyword) against ('The cracy fox jumps over the red cow') as importance
    from db.words
    WHERE match(keyword) against ('The cracy fox jumps over the red cow')
    ORDER BY importance
    LIMIT 2;
    

    否则,您可以使用子查询:

    SELECT keyword
    FROM (SELECT keyword, match(keyword) against ('The cracy fox jumps over the red cow') as importance
          from db.words
          WHERE match(keyword) against ('The cracy fox jumps over the red cow')
          ORDER BY importance
          LIMIT 2
         ) k;
    

    【讨论】:

    • 您好,感谢您的帮助。您确定 mysql 5.x 中存在“matches”命令吗?我找不到这种语法的任何示例,mysql 告诉我该命令是未知的。
    • @merlin 。 . .谢谢你 。语法显然是错误的。我专注于将条件放入where 子句。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 2016-02-01
    相关资源
    最近更新 更多