MySQL 5.5 に mroonga を組込む
前回のMySQL 5.5 ソースからビルドに続いて
全文検索エンジンgroongaのエンジンをインストールします
MySQLに組込む場合はmroonga
と言うそうです。
結構ドキュメントが適当に作られているようで、
試行錯誤しないとインストールが上手くいかないことがわかりました
まずは、ベースであるgroongaをインストールします
pkgconfigが入っていないといけないようなので
インストールしていないのならインストールします
yum -y install pkgconfig
次はドキュメント通りyumのリポジトリをインストールして、
groongaをインストールします。
rpm -ivh http://packages.groonga.org/centos/groonga-repository-1.0.0-0.noarch.rpm yum -y install groonga
ここで問題が生じます
依存関係でmecabがインストールされますが、辞書はインストールされません。
同時に辞書をインストールしておかないと、
組込んだ時にうまく動きません
yum -y install mecab-ipadic
ここで、ドキュメントに載っていないけど
入れておかないと大変なことになるものをインストールします
yum -y install groonga-devel
そうです
mroongaのコンパイルに必要なヘッダファイルのインストールが、
ドキュメントには載っていないが必要です
cd /usr/local/src/ wget https://github.com/downloads/mroonga/mroonga/mroonga-1.11.tar.gz tar zxvf mroonga-1.11.tar.gz cd mroonga-1.11
インストールしないでソースをDLしてソースディレクトリへ入ります
./configure すると
./configure \ --with-mysql-source=/usr/local/src/mysql-5.5.19 \ --with-mysql-config=/usr/local/mysql-5.5.19/bin/mysql_config \ --with-default-parser=TokenMecab
checking for GROONGA... no configure: error: Package requirements (groonga >= 1.2.8) were not met: No package 'groonga' found
と言われます
Alternatively, you may set the environment variables GROONGA_CFLAGS and GROONGA_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.
とか言ってるので
GROONGA_CFLAGS="-I/usr/include/groonga" \ GROONGA_LIBS="-L/usr/lib -lgroonga" \ ./configure \ --with-mysql-source=/usr/local/src/mysql-5.5.19 \ --with-mysql-config=/usr/local/mysql-5.5.19/bin/mysql_config \ --with-default-parser=TokenMecab
とすると、今度は
ha_mroonga.cc:43 から include されたファイル中: mrn_table.h:24:21: error: groonga.h: そのようなファイルやディレクトリはありません
とか言われる
ここで、groonga-develを入れて (make clean & make distcleanしたあと)make すると
hg-not-found clone https://bitbucket.org/birkenfeld/sphinx /usr/local/src/mroonga-1.11/doc/sphinx make[6]: hg-not-found: コマンドが見つかりませんでした
とか
Error: The Docutils library cannot be found. Did you install Sphinx and its dependencies correctly?
とか言われて、
python-docutils とか python-sphinx を入れろと言われるが
結局入れても
Exception occurred: File "/usr/local/src/mroonga-1.11/doc/sphinx/sphinx/util/nodes.py", line 179, in set_source_info directive.state_machine.get_source_and_line(directive.lineno) AttributeError: NestedStateMachine instance has no attribute 'get_source_and_line'
と言われて進まなくなる
実は、ここで必要なのはソースディレクトリの削除と再解凍でソースディレクトリのリセット!
make clean make distclean
してもソースディレクトリが綺麗になってくれないので
いつまでたってもコンパイルが通らない
cd .. rm -rf mroonga-1.11 tar zxvf mroonga-1.11.tar.gz cd mroonga-1.11
としてから
./configure \ --with-mysql-source=/usr/local/src/mysql-5.5.19 \ --with-mysql-config=/usr/local/mysql-5.5.19/bin/mysql_config \ --with-default-parser=TokenMecab
すればすんなりコンパイルが通るようになる
make distclean make clean ではなく ソースディレクトリのリセットが必要
リセットした状態で
上記 ./configure しても
cc1plus: warnings being treated as errors ha_mroonga.cc:1: error: -fprefetch-loop-arrays not supported for this target (try -march switches)
と言われることがある
その場合は、指示に従って
CFLAGS="-march=prescott" \ CXXFLAGS="-march=prescott" \ ./configure \ --with-mysql-source=/usr/local/src/mysql-5.5.19 \ --with-mysql-config=/usr/local/mysql-5.5.19/bin/mysql_config \ --with-default-parser=TokenMecab
-marchを設定してあげるとコンパイルが通る
ただし、-march= つけた ./configure する前にもリセットが必要
make make install
がエラーなく通れば
service mysqld restart
/usr/local/mysql-5.5.19/bin/mysql
INSTALL PLUGIN groonga SONAME 'ha_groonga.so';
CREATE TABLE diaries ( id INT PRIMARY KEY AUTO_INCREMENT, content VARCHAR(255), FULLTEXT INDEX (content) COMMENT 'parser "TokenMecab"' ) ENGINE = groonga COMMENT = 'engine "innodb"' DEFAULT CHARSET utf8; INSERT INTO diaries (content) VALUES ("明日の天気は晴れでしょう。"); INSERT INTO diaries (content) VALUES ("明日の天気は雨でしょう。");
SELECT * FROM diaries WHERE MATCH(content) AGAINST("晴れ"); +----+-----------------------------------------+ | id | content | +----+-----------------------------------------+ | 1 | 明日の天気は晴れでしょう。 | +----+-----------------------------------------+ 1 row in set (0.00 sec)
うむ、OK