【发布时间】:2011-09-16 00:04:40
【问题描述】:
在 mysql 数据库中对全文搜索的搜索结果进行排名时,我遇到了一个小问题(这是我希望的)。我试过用两种方式写它:
自然方式:
SELECT SQL_CALC_FOUND_ROWS *,
MATCH(productname,keywords) AGAINST('$cl_search') AS score
FROM products
WHERE MATCH(productname,keywords) AGAINST('$cl_search')
ORDER BY score DESC,lastupdated DESC;
布尔方式:
SELECT SQL_CALC_FOUND_ROWS *,
((MATCH(productname) AGAINST('$cl_search' IN BOOLEAN MODE))+
(MATCH(keywords) AGAINST('\"$cl_search\"' IN BOOLEAN MODE))) AS score
FROM products
WHERE MATCH(productname,keywords) AGAINST('$cl_search')
ORDER BY score DESC,lastupdated DESC;
我喜欢在自然语言模式下搜索时获得的索引,但如何防止有人输入“bag bag bag bag bag”作为产品名称以获得良好的搜索结果?
所以我写了布尔方法来解决这个问题,但是 1. 它更慢 2. 我没有得到像“与字数相比”这样的其他相关性索引。
关于如何两全其美的想法?
【问题讨论】: