1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLの全文検索でストップワードをオフにする方法

Posted at

目的

MySQLの全文検索(ngram)でストップワード(a,theなど)を利用している場合、ストップワードが含まれる検索ができない。そのため、ストップワードをOFF、インデックスの再構築をして、検索でヒットするように変更する。

例)cat→ca atは両方ともaが含まれ全文検索インデックスに登録されない

現在の設定を確認

mysql> SHOW VARIABLES LIKE 'innodb_ft_enable_stopword';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| innodb_ft_enable_stopword | ON    |
+---------------------------+-------+
1 row in set (0.01 sec)

設定を追加

my.cnf
innodb_ft_enable_stopword=0

再起動

/etc/init.d/mysqld restart

インデックスを再構築

SET GLOBAL innodb_optimize_fulltext_only=ON;
OPTIMIZE TABLE (テーブル名);
SET GLOBAL innodb_optimize_fulltext_only=OFF;
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?