postgresql+textsearch-ja+mecab+ipadicのまとめ

日本語の全文検索が必要になったのでメモ。


 参考



#groupadd postgres
#useradd -g postgres -d /usr/local/pgsql postgres
#passwd postgres
#mkdir /usr/local/pgsql
#chown -R postgres:postgres /usr/local/pgsql

psotrges$./configure
psotrges$make
psotrges$make install

postgres$ vi ~/.bash_profile


export PATH=$PATH:/usr/local/pgsql/bin
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=$POSTGRES_HOME/lib
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
export MANPATH="$MANPATH":$POSTGRES_HOME/man
export PGDATA=/usr/local/pgsql/data



postgres$source ~/.bash_profile
postgres$/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data


mecabのインストール

#./configure --with-charset=utf8


辞書ファイルのインストール
#./configure --with-charset=utf8
#make
#make install



textsearch-jaのインストール

#cp -R textsearch_ja-9.0.0 postgresql-9.1.0/contrib/
#cd postgresql-9.1.0/contrib/textsearch_ja-9.0.0/
#find . -type f -exec sed 's/^\xEF\xBB\xBF//' -i.bak {} \; -exec rm {}.bak \;
#grep -rl $'\xEF\xBB\xBF' ./
#chown postgres:postgres -R /usr/local/src/postgresql-9.1.0
#su postgres
$make
$make install


重要!
下記のSQLを使うDBに実行しないとfunction error
psql -f ./textsearch_ja.sql testtest(DB名)


$vim /usr/local/pgsql/data/postgresql.conf
port = 5432
default_text_search_config = 'pg_catalog.japanese'
listen_addresses = '*'
$vim /usr/local/pgsql/data/pg_hba.conf
host all all 192.168.0.0/24 trust



起動
$ pg_ctl -w start
or
$pg_ctl -o "-S -i" start

停止
$pg_ctl -w stop



共有ライブラリ
vim /etc/ld.so.conf
追記
/usr/local/lib
#ldconfig
#ldconfig -p|grep -i '/usr/local/lib'


テスト
=#create database testtest;


ユーザー追加
$createuser testuser


alter user testuser with password 'testuser';