我有一个使用FULL TEXT索引进行正则表达式匹配的mysql MATCH查询。匹配完成好了。只要我的匹配模式中没有空白区域。例如,这匹配良好:
SELECT * ,
MATCH (
name
)
AGAINST (
'Lady*'
IN BOOLEAN
MODE
) AS SCORE
但这不是:
SELECT * ,
MATCH (
name
)
AGAINST (
'Lady G*'
IN BOOLEAN
MODE
) AS SCORE
它就像我写的那样匹配
SELECT * ,
MATCH (
name
)
AGAINST (
'G*'
IN BOOLEAN
MODE
) AS SCORE
我该如何解决这个问题?
答案 0 :(得分:0)
使用IN NATURAL LANGUAGE MODE而不是BOOLEAN。
mysql> CREATE TABLE articles (
-> id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
-> title VARCHAR(200),
-> body TEXT,
-> FULLTEXT (title,body)
-> ) ENGINE=MyISAM;
Query OK, 0 rows affected (0.08 sec)
mysql> INSERT INTO articles (title,body) VALUES
-> ('MySQL Tutorial','DBMS stands for DataBase ...'),
-> ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
-> ('MySQL Security','When configured properly, MySQL ...');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM articles
-> WHERE MATCH (title,body)
-> AGAINST ('stands for' IN NATURAL LANGUAGE MODE);
+----+----------------+------------------------------+
| id | title | body |
+----+----------------+------------------------------+
| 1 | MySQL Tutorial | DBMS stands for DataBase ... |
+----+----------------+------------------------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('stands fo*' IN NATURAL LANGUAGE MODE);
+----+----------------+------------------------------+
| id | title | body |
+----+----------------+------------------------------+
| 1 | MySQL Tutorial | DBMS stands for DataBase ... |
+----+----------------+------------------------------+
1 row in set (0.00 sec)