まとめました

.. vim: syn=rst

=======================
Senna + MySQL + Tritonn
=======================

動作環境
========

**VMware Server 1.0.2**

- Debian GNU/Linux etch Testing
- Ubuntu 7.04 Server Beta
- Ubuntu 6.10 Server

`mecab-0.95`_
`mecab-ipadic-2.7.0-20060707`_

`senna-1.0.3`_
`tritonn-1.0.1.mysql-5.0.37.senna-1.0.3`_
`mysql-5.0.37`_

.. _mecab-0.95: http://mecab.sourceforge.net/
.. _mecab-ipadic-2.7.0-20060707 : http://mecab.sourceforge.net/
.. _senna-1.0.3: http://qwik.jp/senna/FrontPageJ.html
.. _tritonn-1.0.1.mysql-5.0.37.senna-1.0.3: http://qwik.jp/tritonn/
.. _mysql-5.0.37: http://www-jp.mysql.com/

::
    su -
    aptitude install gcc g++ make patch \
    bison autotools autoconf automake1.9 libtool libncurses-dev

mecab-0.95
==========

::

    ./configure --prefix=/usr \
    --with-charset=utf8 --enable-utf8-only
    make
    make install

mecab-ipadic-2.7.0-20060707
===========================

::

    ./configure --prefix=/usr \
    --with-charset=utf8 --enable-utf8-only
    make
    make install

Mecab(和布蕪)動作確認
=====================

::

    mecab
    すもももももももものうち
    すもも  名詞,一般,*,*,*,*,すもも,スモモ,スモモ
    も      助詞,係助詞,*,*,*,*,も,モ,モ
    もも    名詞,一般,*,*,*,*,もも,モモ,モモ
    も      助詞,係助詞,*,*,*,*,も,モ,モ
    もも    名詞,一般,*,*,*,*,もも,モモ,モモ
    の      助詞,連体化,*,*,*,*,の,ノ,ノ
    うち    名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
    EOS

senna-1.0.3
===========

::

    ./configure --prefix=/usr
    make
    make install

mysql-5.0.37
============

*疑問*

--enable-skip-character-set-client-handshakeって本当にあるのだろうか、
かなり怪しいので一応外しておいた。一応入れてもmakeは通ってますが...。

情報求む。

::
    patch -p1 < ../tritonn-1.0.1.mysql-5.0.37.senna-1.0.3/mysql-5.0.37.senna.diff

    libtoolize -c -f
    aclocal-1.9
    autoheader
    automake-1.9 -c -a -i
    autoconf
    touch sql/sql_yacc.yy

    CFLAGS="-O3" \
    CXX=gcc CXXFLAGS="-O3 \
    -felide-constructors -fno-exceptions -fno-rtti" \
    ./configure \
    --prefix=/usr/local/mysql \
    --localstatedir=/usr/local/mysql/data \
    --libexecdir=/usr/local/mysql/bin \
    --enable-thread-safe-client \
    --enable-local-infile \
    --enable-assembler \
    --disable-shared \
    --with-charset=utf8 --with-extra-charsets=complex \
    --with-mysql-user=mysql \
    --with-big-tables \
    --with-yassl \
    --with-readline \
    --with-federated-storage-engine \
    --with-innodb \
    --with-zlib-dir=bundled \
    --with-pic \
    --with-fast-mutexes \
    --with-senna --with-mecab

    make
    make install

    groupadd mysql
    useradd mysql -g mysql
    cp -p ./support-files/my-medium.cnf /etc/my.cnf
    ./scripts/mysql_install_db
    chown -R mysql:mysql /usr/local/mysql
    chmod 755 /usr/local/mysql
    cp -p ./support-files/mysql.server /etc/init.d/mysql
    chmod +x /etc/init.d/mysql
    /etc/init.d/mysql start
    
    exit

/usr/local/mysql/bin に PATH を通してください。

文字化け問題
============

MySQLは文字化けが怖いのでutf8で統一されているかの確認

::

    mysql> status;
    ...
    Server characterset:    utf8
    Db     characterset:    utf8
    Client characterset:    utf8
    Conn.  characterset:    utf8
    ...

    mysql> SHOW VARIABLES LIKE 'character\_set\_%';
    +--------------------------+--------+
    | Variable_name            | Value  |
    +--------------------------+--------+
    | character_set_client     | utf8   |
    | character_set_connection | utf8   |
    | character_set_database   | utf8   |
    | character_set_filesystem | binary |
    | character_set_results    | utf8   |
    | character_set_server     | utf8   |
    | character_set_system     | utf8   |
    +--------------------------+--------+

skip-character-set-client-handshake を追記する

::

    vim /etc/my.cnf

    [mysqld]
    skip-character-set-client-handshake

参考 `文字化け問題を本気で直す`_

.. _`文字化け問題を本気で直す` : http://wota.jp/ac/?date=20061011


MySQLバインディングを用いた動作確認例
=====================================

参考文献というかそのまま `Senna 組み込み型全文検索エンジン - 動作確認方法`_ 

.. _`Senna 組み込み型全文検索エンジン - 動作確認方法` : http://qwik.jp/senna/check_install.html

CREATE TABLEの確認::

    create database senna_test;
    use senna_test;
    CREATE TABLE michilu (
        id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY(id),
        title VARCHAR(255),
        body TEXT,
        FULLTEXT(body)
    ) ENGINE = MyISAM DEFAULT CHARSET utf8;

INSERTの確認::

    INSERT INTO michilu VALUES
    (NULL, "views.py書いたら負けだと思っている", "まちがって、LT作ったのでUPしちゃう");

全文検索WHERE MATCHの確認::

    SELECT * FROM michilu WHERE MATCH(body) AGAINST('UPしちゃう');

UPDATEの確認::

    UPDATE michilu SET body = '超稲妻3倍迅い??' WHERE id = 1;
    SELECT * FROM michilu WHERE MATCH(body) AGAINST('稲妻');