サイトのコンテンツが増えてくると目的のコンテンツへ導くために全文検索システムがあるとよい(自分も便利!)です。当サイトではNamazuというフリーウェアを用いて全文検索システムを構築しています。
英語では、単語と単語の区切りにはスペースが入るため、簡単に単語を切り出すことができますが、日本語ではスペースが入らないため、単語を識別して切り出す処理が必要になります。これをわかち処理といいます。Namazuでは、日本語の検索わかち処理にChasenかKAKASIを利用します。ここではKAKASIを用いることにします。
% tar zxvf kakasi-x.y.z.tar.gz % cd kakasi-x.y.z % ./configure % make % su # make install
% tar zxvf namazu-a.b.c.tar.gz % cd namazu-a.b.c % ./configureここで以下のようなメッセージが表示されると思います。
checking for File::MMagic perl module... Can't locate File/MMagic.pm in
@INC (@INC contains: . /usr/libdata/perl/5.00503/mach
/usr/libdata/perl/5.00503
/usr/local/lib/perl5/site_perl/5.005/i386-freebsd
/usr/local/lib/perl5/site_perl/5.005 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
no
configure: error: you need to install the included File-MMagic first
The simplest way to install File-MMagic is:
% cd File-MMagic
% perl Makefile.PL
% make
% su
# make install
Then, simply run configure again.
% cd ..
% ./configure
Or you can install File-MMagic to your home directory by the following way:
% cd File-MMagic
% perl Makefile.PL LIB=/home/yuji/lib INSTALLMAN3DIR=/home/yuji/man
% make
% make install
Then, run configure again with --with-pmdir=DIR option.
% cd ..
% ./configure --with-pmdir=/home/yuji/lib
ここはおとなしく指示にしたがってFile-MMagicをインストールします。
% cd File-MMagic % perl Makefile.PL % make % su # make installこれで
File-MMagicがインストールされました。次はいよいよNamazuの番です。
% cd .. % ./configure % make % su # make installこれにてインストール完了!
インストールされたnamazu.cgiをcgiが実行できるディレクトリに設置します。大抵は、/usr/local/libexec/namazu.cgiを/usr/local/apache/cgi-bin以下にコピーすることになります。
# cp -p /usr/local/libexec/namazu.cgi /usr/local/apache/cgi-bin/
/usr/local/etc/namazu/mknmzrc-sampleを参考に、以下のように修正します。
package conf; # Don't remove this line! $ADDRESS = 'webmaster@ykondou.org'; $NKF = "/path/to/nkf"; # 日本語のフィルタを指定 $KAKASI = "/path/to/kakasi -inewjis -onewjis -w"; # ファイルの入出力の文字コードを指定 $WAKATI = $KAKASI; # わかち処理のプログラムを指定
/usr/local/etc/namazu/namazurc-sampleを参考に、以下のように修正します。
Index /path/to/namazu # インデックスのあるディレクトリを指定 Template /path/to/namazu # 検索結果の出力のためのテンプレートのあるディレクトリを指定 Logging on # 検索キーワードのログを取る場合はon Lang ja # テンプレートに用いるファイルを指定
namazu.cgiを設置したディレクトリに、作成した/usr/local/etc/namazu/namazurcを.namazurcとしてコピーします。