VineLinuxパフォーマンスアッププロジェクト:0147

■全文検索システムnamazuをインストールしてみよう!(2)■

 全文検索システムnamazuをインストールしてみよう!(1)ではnamazuの導入から基本的な操作方法までについて紹介しましたが、今回はhtml経由で検索結果を表示させたりインデックス作成を自動化する方法について紹介したいと思います。


★htmlフォームの作成

 namazuのいい点はWebページなどから即座に検索し、結果を表示することができる点です。サンプルとして当サイトで使用しているhtmlフォームを置いておきますのでこちらからご自由にお使いください(アドレスや検索ボタン名などはご自分の環境に合わせて変更してください)。

 次に、namazu.cgiをコピーさせます。これまでの環境に沿って作成した場合、インデックス更新ごとに以下のコマンドを実行してください。

★VineLinux4.2までの場合
  cp -f /home/httpd/cgi-bin/namazu.cgi /home/httpd/html/cgi-bin/namazu.cgi

★VineLinux5.0以降の場合
  cp -f /var/www/cgi-bin/namazu.cgi /home/httpd/html/cgi-bin/namazu.cgi

 さらに、設定ファイルである.namazurcを編集します。namazu.cgiと同じディレクトリ内(/home/httpd/cgi-bin/または/var/www/cgi-bin/)にありますのでそれをテキストエディタ等で編集します。以下の赤字部分をご自分の環境に合わせて変更してください。
#
#  /XXXXXXX/XXXXXXX/cgi-bin/.namazurc for Vine Linux
#
#  Each item is must be separated by one or more SPACE or TAB characters.
#  You can use a double-quoted string for represanting a string which
#  contains SPACE or TAB characters like "foo bar baz".

##
## Index: Specify the default directory.
##
Index         /home/httpd/namazu/index

# This is the directory in which Vine namazu_*db packages are installed.

##
## Template: Set the template directory containing
## NMZ.{head,foot,body,tips,result} files.
##
Template      /home/httpd/namazu/index

# This is the directory in which Vine namazu templates are installed.

##
## Replace: Replace TARGET with REPLACEMENT in URIs in search
## results.
##
## TARGET is specified by perl-like regular expressions.
## You can caputure sub-strings in TARGET by surrounding them
## with `(' and `)'and use them later as backreferences by
## \1, \2, \3,... \9.
##
## To use meta characters literally such as `*', `+', `?', `|',
## `[', `]', `{', `}', `(', `)', escape them with `\'.
##
## e.g.,
##
##    Replace  /home/foo/public_html/   http://www.foobar.jp/~foo/
##    Replace  /home/(.*)/public_html/  http://www.foobar.jp/\1/
##    Replace   /C\|/foo/               http://www.foobar.jp/
##
## If you do not want to do the processing on command line use,
## run namazu with -U option.
##
Replace        /usr/doc/               file:///usr/doc/
Replace        /usr/share/             file:///usr/share/
Replace        /home/httpd/html/       http://mkserver.dip.jp/

##
## Logging: Set OFF to turn off keyword logging to NMZ.slog.
## Default is ON.
##
Logging       off


##
## Lang: Set the locale code such as `ja_JP.eucJP', `ja_JP.SJIS',
## `de', etc.  This directive works only if the environment
## variable LANG is not set because the directive is mainly
## intended for CGI use.  On the shell, You can set
## environemtnt variable LANG instead of using the directive.
##
## If you set `de' to it, namazu.cgi use
## NMZ.(head|foot|body|tips|results).de for displaying results
## and use a proper message catalog for `de'.
##
Lang          ja_JP.eucJP


##
## Scoring: Set the scoring method "tfidf" or "simple".
##
Scoring       tfidf


##
## EmphasisTags: Set the pair of html elements which is used in
## keyword emphasizing for search results.
##
#EmphasisTags  "<strong class=\"keyword\">"   "</strong>"

★検索結果表示のカスタマイズ

 html経由で検索を行った場合、検索結果もhtmlで表示されます。その検索結果を表示させるためのページソースはデフォルトのままではちょっとさみしいレイアウトとなっています。そこでこれらの外観を変更したい場合には以下の各ファイルを編集してください。これらは/home/httpd/namazu/index以下にあります。

ファイル名 設定内容
NMZ.head.ja html上部(ヘッダ部分)の設定。
NMZ.body.ja namazu.cgi呼び出し時に表示される。
NMZ.foot.ja html下部の設定。
namazuのバージョンや管理者連絡の設定。
NMZ.result.normal.ja 検索結果表示が標準モード時の設定。
NMZ.result.short.ja 検索結果表示が簡潔モード時の設定。
NMZ.tips.ja 検索結果がないときの表示設定。


★インデックス作成の自動化

 インデックス作成は定期的に行う必要があります。そこでこの処理を自動化させましょう。

 インデックス作成シェルスクリプトがありますのでこちらからダウンロードして中身をご自分の環境に合わせて編集後、実行権限をつけてください。

 ここでは/root以下にダウンロードして実行権限をつけたとします。その後、/etc/crontabを開き自動実行の記述を追加します。例えば、毎時15分にnamazu-index.shを実行したい場合には

  15 * * * * root /root/namazu-index.sh

 と記述し、crondを再スタートさせればOKです。

お疲れさまでした。以上でnamazuの導入が完了しました。あとはシステム自体の再起動を行い、正常に動作すればOKです。

●Special Thanks! 日本語全文検索システム Namazu の導入
http://www.miloweb.net/namazu.html





プロジェクト ホームへ戻る