我必须在多个列中实现全文搜索,并根据某些列/字段的相关性进行结果加权。
我遇到的所有解决方案似乎都使用单列索引来计算相关性,并使用一个多列索引来计算WHERE
子句。请参阅:https ://stackoverflow.com/a/600915/168719或https://stackoverflow.com/a/6305108/168719
这是我的查询:
SELECT MATCH(name) AGAINST (text) as relevance_name,
MATCH(description) AGAINST(text) as relevance_description,
MATCH(description_long) AGAINST (text) as relevance_description_long
FROM products WHERE
我面临着以下选择:
一个)
MATCH(name, description, description_long) AGAINST (text) > 0
b)
MATCH(name) AGAINST (text) > 0
OR MATCH(description) AGAINST (text) > 0
OR MATCH(description_long) AGAINST (text) > 0
之后是排序子句。
ORDER BY (relevance_name * 2 +
relevance_description * 3 +
relevance_description_long * 4) / 9
问题是 - a(显然是首选方法)优于b的优势是什么?
a需要创建另一个全文索引(跨所有可搜索列),这显然会占用更多磁盘空间。
有什么优势?是性能问题吗?还是搜索质量?