gpt4 book ai didi

mysql - 如何在where子句中执行带有单引号的mysql全文搜索查询?

转载 作者:行者123 更新时间:2023-11-30 23:49:12 24 4
gpt4 key购买 nike

我正在使用全文搜索,查询在 where 子句中有单引号,它返回值但不准确。

SELECT `id`, `itemid`, `title`, 
MATCH( `itemid`, `title`, `product_id`,`p1_name`, `p2_name`, `p3_name`, `p4_name` )
AGAINST ( "men\'s" IN BOOLEAN MODE ) AS score FROM `deals`
WHERE `active_flag`='1' AND
MATCH( `itemid`, `title`, `product_id`,`p1_name`, `p2_name`, `p3_name`, `p4_name`)
AGAINST ( "men\'s" IN BOOLEAN MODE ) !=0
ORDER BY score DESC

它应该返回关键字恰好是“Men's”(不包括 "双引号)的情况。但它返回存在 men 和 s 的情况?

谁能帮帮我?

谢谢。

最佳答案

它最有可能是因为 MyISAM 全文的内部停用词列表。

根据 this documentation

The variable value should be the path name of the file containing the stopword list, or the empty string to disable stopword filtering. The server looks for the file in the data directory unless an absolute path name is given to specify a different directory. After changing the value of this variable or the contents of the stopword file, restart the server and rebuild your FULLTEXT indexes.

我在我的ini文件中改变了这个

+ft_stopword_file = C:\ProgramData\MySQL\MySQL Server 5.6/mysql_ft_stopword_file.txt

然后重新启动服务器,即使文件不存在它也会启动,所以你不必创建一个。重启后必须重建表。

我现在设法使用此查询获得结果

SELECT * FROM test.fttest 
WHERE MATCH(txt) AGAINST("men's" IN BOOLEAN MODE);

还有这个

SELECT * FROM test.fttest 
WHERE MATCH(txt) AGAINST('men\'s' IN BOOLEAN MODE);

如果您有大量数据,稍后构建您自己的停用词列表可能是个好主意,因为没有词被视为停用词,因此索引会变得更大。

关于mysql - 如何在where子句中执行带有单引号的mysql全文搜索查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20684808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com