我在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;
Run Code Online (Sandbox Code Playgroud)
布什方式:
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;
Run Code Online (Sandbox Code Playgroud)
我喜欢在自然语言模式下搜索时获得的索引但是如何防止有人进入"袋袋包袋"作为产品名称以获得良好的搜索结果?
所以我写了一个布尔方式来解决这个问题但是1.它更慢而且2.我没有得到其他相关性索引,比如'与字数相比'.
关于如何充分利用这两个世界的任何想法?