【发布时间】:2017-11-11 15:06:45
【问题描述】:
可以说我有表 posts 与这些列:
top_totle,title,sub_title,text
我需要对所有此列进行全文搜索,并按相关性排序,其中 top_title 需要比标题等更重要。
所以我有 2 个相同的问题,为此创建索引的最佳方法是什么以及如何格式化查询以最好地支持该索引?
索引选项: 我可以在此列的所有内容上创建组合全文索引,也可以为每个列创建单独的索引
哪个是首选方式? 选项1:
SELECT
title,
MATCH (top_title) AGAINST ('text' IN BOOLEAN MODE) as toptitle_score,
MATCH (title) AGAINST ('text' IN BOOLEAN MODE) as title_score,
MATCH (sub_text) AGAINST ('text' IN BOOLEAN MODE) as sub_text_score,
FROM
`posts`
WHERE
MATCH (top_title,title , sub_text ) AGAINST ('text' IN BOOLEAN MODE)
and `posts`.`deleted_at` IS NULL
AND `published_at` IS NOT NULL
Order by toptitle_score desc,
Order by title_score desc ,
Order by subtext_score desc
选项 2:
SELECT
title,
MATCH (top_title) AGAINST ('text' IN BOOLEAN MODE) as toptitle_score,
MATCH (title) AGAINST ('text' IN BOOLEAN MODE) as title_score,
MATCH (sub_text) AGAINST ('text' IN BOOLEAN MODE) as sub_text_score,
FROM
`posts`
WHERE
(MATCH (top_title) AGAINST ('text' IN BOOLEAN MODE)
or MATCH (title) AGAINST ('text' IN BOOLEAN MODE)
or MATCH (sub_text) AGAINST ('text' IN BOOLEAN MODE))
and `posts`.`deleted_at` IS NULL
AND `published_at` IS NOT NULL
Order by toptitle_score desc,
Order by title_score desc ,
Order by subtext_score desc
选项 3:
is there some smarter way?
【问题讨论】:
标签: mysql full-text-search innodb mariadb full-text-indexing