我想在给定文本中突出显示最多2个单词。搜索关键字来自mysql表,其中包含数百种可能的匹配项和重要性信息。
例如:" cracy fox跳过红牛"mysql table" words"可能的比赛:
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
感谢您提供有关如何实现此目标的任何提示!
答案 0 :(得分:0)
如果您不介意输出重要性:
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;