# MySQLで全文検索を試してみたかったんです。
CentOS 6を利用しているので、MySQLは下記のバージョンを使用しています。
1 2 | % rpm -q "mysql-*" mysql-5.1.61-1.el6_2.1.x86_64 |
MySQLで日本語の全文検索をするために、MySQL full-text parser plugin collectionのmecab pluginを使ってみることにしました。
上記のソフトを付属のINSTALLファイルを参照して、インストールします。
ロケールにUTF8を使用しているので、mecab-0.993, mecab-ipadic-2.7.0-20070801のconfigureのオプションに
--with-charset=utf8
を指定する必要がありました。(デフォルトはEUC)
取りあえず、こんな感じでテーブルを作ると、
1 2 3 4 5 6 7 8 9 10 11 | create table da_caption ( dp_id integer primary key NOT NULL AUTO_INCREMENT, dc_ch integer , dp_start_time timestamp , dp_pid integer , dv_id integer , dp_text text ) engine = myisam DEFAULT CHARSET=utf8 COLLATE =utf8_unicode_ci; create index da_caption_index on da_caption (dp_start_time, dc_ch); create fulltext index da_caption_fulltext_index on da_caption (dp_text) with parser mecab; |
1 2 3 4 5 6 7 8 9 10 11 | mysql> select * from da_caption where match(dp_text) against( 'バイク -自転車' in boolean mode) limit 5; + ---------+-------+---------------------+--------+--------+--------------------------------------------------------------------------------------------+ | dp_id | dc_ch | dp_start_time | dp_pid | dv_id | dp_text | + ---------+-------+---------------------+--------+--------+--------------------------------------------------------------------------------------------+ | 2337207 | 27 | 2012-03-31 16:19:30 | 1415 | 190710 | 同じ排気量のバイクに乗るため→ | | 2337241 | 27 | 2012-03-31 16:22:40 | 1415 | 190710 | でも ほとんど バイクのパーツ代に消えてしまうんだそうです。 | | 2399738 | 23 | 2012-04-01 19:54:08 | 4231 | 194390 | 知人らしきバイクの女性が颯爽と登場。 | | 2380118 | 21 | 2012-04-01 13:01:38 | 340 | 193580 | <ベトナムは バイク大国> | | 2380122 | 21 | 2012-04-01 13:02:03 | 340 | 193580 | <バイクの多い…> | + ---------+-------+---------------------+--------+--------+--------------------------------------------------------------------------------------------+ 5 rows in set (0.00 sec) |
0 件のコメント:
コメントを投稿