Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 全文搜索排名_Mysql_Full Text Search - Fatal编程技术网

Mysql 全文搜索排名

Mysql 全文搜索排名,mysql,full-text-search,Mysql,Full Text Search,我在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

我在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”作为产品名称以获得良好的搜索结果

所以我写了一个布尔方法来解决这个问题,但是1。它是慢的和2。我没有其他相关索引,比如“与字数相比”


有没有想过如何做到两全其美呢?

非常简单,改用Lucene,它更先进,当然可以选择处理您想要的内容。

编写一个用户定义的函数,删除重复的关键字怎么样? 那么您的查询将是什么样子:

SELECT SQL_CALC_FOUND_ROWS *,
 MATCH(productname,RM_DUP(keywords)) AGAINST('$cl_search') AS score 
 FROM products 
  WHERE MATCH(productname,RM_DUP(keywords)) AGAINST('$cl_search') 
  ORDER BY score DESC,lastupdated DESC;