Skip to content

Instantly share code, notes, and snippets.

@pruet
Created May 28, 2016 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pruet/4a212c0c64e1874aac52c3ccb86a39f4 to your computer and use it in GitHub Desktop.
Save pruet/4a212c0c64e1874aac52c3ccb86a39f4 to your computer and use it in GitHub Desktop.
Test ngram with Thai
mysql> drop table if exists articles;
Query OK, 0 rows affected (0.45 sec)
mysql> create table articles (
-> id int unsigned auto_increment not null primary key,
-> title varchar(200),
-> body text,
-> FULLTEXT (title, body) WITH PARSER ngram
-> ) engine=innodb character set utf8;
Query OK, 0 rows affected (1.41 sec)
mysql>
mysql> insert into articles(title, body) values ('วันนี้ฝนไม่ตก', 'วันนี้ฝนไม่ตก');
Query OK, 1 row affected (0.03 sec)
mysql> insert into articles(title, body) values ('พรุ่งนี้แดดออก', 'พรุ่งนี้แดดออก');
Query OK, 1 row affected (0.03 sec)
mysql> insert into articles(title, body) values ('เมื่อวานหิมะตก', 'เมื่อวานหิมะตก');
Query OK, 1 row affected (0.05 sec)
mysql> insert into articles(title, body) values ('ปีหน้ารวย', 'ปีหน้ารวย');
Query OK, 1 row affected (0.08 sec)
mysql>
mysql>
mysql> SELECT * FROM articles
-> WHERE MATCH (title,body)
-> AGAINST ('นี้' IN NATURAL LANGUAGE MODE);
+----+--------------------------------------------+--------------------------------------------+
| id | title | body |
+----+--------------------------------------------+--------------------------------------------+
| 1 | วันนี้ฝนไม่ตก | วันนี้ฝนไม่ตก |
| 2 | พรุ่งนี้แดดออก | พรุ่งนี้แดดออก |
+----+--------------------------------------------+--------------------------------------------+
2 rows in set (0.03 sec)
mysql> drop table if exists articles;
Query OK, 0 rows affected (0.49 sec)
mysql> create table articles (
-> id int unsigned auto_increment not null primary key,
-> title varchar(200),
-> body text,
-> FULLTEXT (title, body) #WITH PARSER ngram
-> ) engine=innodb character set utf8;
Query OK, 0 rows affected (1.80 sec)
mysql>
mysql> insert into articles(title, body) values ('วันนี้ฝนไม่ตก', 'วันนี้ฝนไม่ตก');
Query OK, 1 row affected (0.03 sec)
mysql> insert into articles(title, body) values ('พรุ่งนี้แดดออก', 'พรุ่งนี้แดดออก');
Query OK, 1 row affected (0.03 sec)
mysql> insert into articles(title, body) values ('เมื่อวานหิมะตก', 'เมื่อวานหิมะตก');
Query OK, 1 row affected (0.04 sec)
mysql> insert into articles(title, body) values ('ปีหน้ารวย', 'ปีหน้ารวย');
Query OK, 1 row affected (0.06 sec)
mysql>
mysql>
mysql> SELECT * FROM articles
-> WHERE MATCH (title,body)
-> AGAINST ('นี้' IN NATURAL LANGUAGE MODE);
Empty set (0.01 sec)
mysql>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment