我创建了一个这样的索引:
ALTER TABLE `blog_posts`
ADD FULLTEXT `title_description_content` (`title`, `description`, `content`);
我可以搜索:
SELECT * FROM `blog_posts`
WHERE MATCH(title, content, description)
AGAINST("lorem ipsum" IN NATURAL LANGUAGE MODE)
LIMIT 12
但我想按栏得分。例如,标题列值3分,描述值2分,内容值1分。因此,在标题中找到的单词得分更高。
我知道这是可能的,因为我已经做过一次了,但我失去了来源,在谷歌上找不到任何例子。
谢谢!
您可以为问题使用多个索引
SELECT *,
MATCH (title) AGAINST ("lorem ipsum" IN NATURAL LANGUAGE MODE) AS rel1,
MATCH (content) AGAINST ("lorem ipsum" IN NATURAL LANGUAGE MODE) AS rel2,
MATCH (description) AGAINST ("lorem ipsum" IN NATURAL LANGUAGE MODE) AS rel3
FROM `blog_posts`
WHERE MATCH(title, content, description) AGAINST("lorem ipsum" IN NATURAL LANGUAGE MODE)
ORDER BY (rel1 * 3)+(rel2 * 2)+(rel3 * 1) DESC
LIMIT 12
加权倍数可以微调