1
ajaxgoldfish 2022-11-19 08:08:41 +08:00 via Android
我猜,转译 ascll 码
|
2
ajaxgoldfish 2022-11-19 08:11:13 +08:00 via Android
百度上的 1 、查询带有中文标点符号,使用 COLLATE Chinese_PRC_CS_AS_WS ,注意在%%中间输入就要是中文符号。
select * from TASK where info COLLATE Chinese_PRC_CS_AS_WS like '%,%' |
3
ajaxgoldfish 2022-11-19 08:12:12 +08:00 via Android
@ajaxgoldfish 大意了,没看题,各位请无视我
|
4
brader 2022-11-19 10:13:17 +08:00
刚测试了一下,是可以达到你这个效果的。你再试试。
CREATE TABLE posts ( id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(255), body TEXT, FULLTEXT ( title , body ) WITH PARSER NGRAM ) ENGINE=INNODB CHARACTER SET UTF8MB4; INSERT INTO posts(title,body) VALUES('MySQL 全文搜索','MySQL 提供了具有许多好的功能的内置全文搜索'), ('MySQL 教程','学习 MySQL 快速,简单和有趣'); SELECT * FROM posts WHERE MATCH (title , body) AGAINST ("快速,简单" IN BOOLEAN MODE); |
5
brader 2022-11-19 10:15:57 +08:00
注意使用 show variables like "%ft%" 和 show variables like "%ngram_token_size%",查看你设置的分词粒度
|
6
brader 2022-11-19 10:29:41 +08:00
对了,如果上面那个搜索语句找不到,而你仅仅需要查包含这样的简单场景,还是使用 SELECT * FROM posts WHERE MATCH (title , body) AGAINST ("速," IN natural language MODE); 会好点,分词粒度看你需要,可以设置为 2 ,甚至是 1
|
7
Jiangoogle OP @brader 不行啊,可能是因为你用的是 InnoDB ?
我的环境是:mysql5.7.20 ,MyISAM , 配置是:ft_stopword_file = '',ngram_token_size = 2 CREATE TABLE `tmp` (`book_name` char(32) NOT NULL, FULLTEXT KEY `book_name` (`book_name`) WITH PARSER `ngram`) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; insert into tmp values('你好,我的'); mysql> select book_name from tmp where match(book_name) against('"你好,"' in boolean mode) ; +-----------------+ | book_name | +-----------------+ | 你好,我的 | +-----------------+ 1 row in set (0.00 sec) mysql> select book_name from tmp where match(book_name) against('"你好,我的"' in boolean mode); Empty set (0.00 sec) mysql> select book_name from tmp where match(book_name) against('"你好"' in boolean mode); +-----------------+ | book_name | +-----------------+ | 你好,我的 | +-----------------+ 1 row in set (0.00 sec) 就上边这三种情况,不知道为什么 |
8
Jiangoogle OP 继续求助
|