差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
dokuwiki:localize [2005/12/05 13:38] – osamu | dokuwiki:localize [2007/07/31 15:36] (現在) – osamu | ||
---|---|---|---|
行 1: | 行 1: | ||
====== DokuWikiの日本語対応 ====== | ====== DokuWikiの日本語対応 ====== | ||
- | [[doku> | + | [[doku> |
<code php> | <code php> | ||
$conf[' | $conf[' | ||
</ | </ | ||
- | と記述すると、ユーザーインターフェースの文字列などは日本語になる。 | + | と記述されて、ユーザーインターフェースの文字列などは日本語になる。 |
機能面での日本語対応を強化するために、次の改造を加える。 | 機能面での日本語対応を強化するために、次の改造を加える。 | ||
行 72: | 行 72: | ||
^D</ | ^D</ | ||
のように、入力した文字が分かち書きされて表示されればOK。 | のように、入力した文字が分かち書きされて表示されればOK。 | ||
+ | |||
+ | |||
+ | |||
+ | |||
行 92: | 行 96: | ||
function idx_getPageWords($page)の | function idx_getPageWords($page)の | ||
<code php> | <code php> | ||
- | | + | |
</ | </ | ||
- | の後ろに | + | と |
+ | <code php> | ||
+ | $body = strtr($body, | ||
+ | </ | ||
+ | の間に | ||
<code php> | <code php> | ||
| | ||
行 104: | 行 112: | ||
$process = proc_open(PRE_TOKENIZER, | $process = proc_open(PRE_TOKENIZER, | ||
if(is_resource($process)) { | if(is_resource($process)) { | ||
+ | stream_set_blocking($pipes[0], | ||
+ | stream_set_blocking($pipes[1], | ||
fwrite($pipes[0], | fwrite($pipes[0], | ||
fclose($pipes[0]); | fclose($pipes[0]); | ||
+ | |||
+ | $body = ''; | ||
+ | while(!feof($pipes[1])) { | ||
+ | $body .= fgets($pipes[1], | ||
+ | } | ||
+ | fclose($pipes[1]); | ||
+ | proc_close($process); | ||
} | } | ||
- | $body = ''; | ||
- | while(!feof($pipes[1])) { | ||
- | $body .= fgets($pipes[1], | ||
- | } | ||
- | fclose($pipes[1]); | ||
- | proc_close($process); | ||
} | } | ||
</ | </ | ||
行 131: | 行 142: | ||
$process = proc_open(PRE_TOKENIZER, | $process = proc_open(PRE_TOKENIZER, | ||
if(is_resource($process)) { | if(is_resource($process)) { | ||
+ | stream_set_blocking($pipes[0], | ||
+ | stream_set_blocking($pipes[1], | ||
fwrite($pipes[0], | fwrite($pipes[0], | ||
fclose($pipes[0]); | fclose($pipes[0]); | ||
+ | $string = ''; | ||
+ | while(!feof($pipes[1])) { | ||
+ | $string .= fgets($pipes[1], | ||
+ | } | ||
+ | fclose($pipes[1]); | ||
+ | proc_close($process); | ||
} | } | ||
- | $string = ''; | ||
- | while(!feof($pipes[1])) { | ||
- | $string .= fgets($pipes[1], | ||
- | } | ||
- | fclose($pipes[1]); | ||
- | proc_close($process); | ||
} | } | ||
</ | </ | ||
を追加。 | を追加。 | ||
+ | DokuWikiの最近のバージョンでは、日本語を含むアジア圏の文字を1文字1単語とみなして検索する修正が入っているが、これを使うと例えば「文字を探す」で検索すると「文」「字」「を」「探」「す」のすべての文字が検索結果でハイライトされたりして具合がよくない。上記の修正を加えたときは、idx_tokenizer($string,& | ||
+ | <code php> | ||
+ | $asia = @preg_replace('/ | ||
+ | if(!is_null($asia)) $word = $asia; //recover from regexp failure | ||
+ | </ | ||
+ | という2行をコメントアウトする。 | ||
+ | また、indexer.phpにwordlen()という関数があるが、これも同じくアジア圏の文字は1文字1単語とみなす処理が入っているので | ||
+ | <code php> | ||
+ | function wordlen($w){ | ||
+ | // $l = strlen($w); | ||
+ | $l = utf8_strlen($w); | ||
+ | |||
+ | //// If left alone, all chinese " | ||
+ | //// So the " | ||
+ | // | ||
+ | // $l += ord($w) - 0xE1; // Lead bytes from 0xE2-0xEF | ||
+ | |||
+ | return $l; | ||
+ | } | ||
+ | </ | ||
+ | と変更。 | ||
+ | |||
+ | それから、同じくindexer.php の idx_getIndexWordsSorted() 関数の中に、 | ||
+ | <code php> | ||
+ | if ($wlen < 3 && $wild == 0 && !is_numeric($xword)) continue; | ||
+ | </ | ||
+ | という部分があるが、このままだと3文字より短い単語を検索できない。英語などではそれでもよいのだが、日本語の場合1~2文字の単語も検索できないと困るので、これを | ||
+ | <code php> | ||
+ | if (preg_match('/ | ||
+ | </ | ||
+ | と書き換える。 | ||
+ | //2005-12-8 - Mecabのプロセスがハングアップして残ってしまうのを避けるために'' | ||
+ | //2007-7-29 - DokuWikiの最近のバージョンにあわせて、修正箇所の説明を変更// | ||
行 165: | 行 211: | ||
http:// | http:// | ||
- | + | // 追記: | |
- | + | ||
- | ==== テンプレートの変更 ==== | + | |
- | 検索の機能はこれで働くようになるのだが、ヒット数の多いサイトの場合、このままではサーバーの負荷がかなり重くなるはず。 | + | |
- | DokuWikiでは、ページを誰かが表示するたびに、そのページの検索インデックスを作り直す仕組みになっている。もともと全文検索のインデックス更新は軽い仕事ではない上に、この改造で毎回Mecabを動かすことになって、負荷が大きくなっている。 | + | |
- | あまりきれいな解決策ではないけれど、とりあえずQuick Hackで、検索インデックスの更新を「ときどき」行うようにする。 | + | |
- | 表示のたびにインデックスを更新するしくみは、標準添付のテンプレート'' | + | |
- | <code php> | + | |
- | <?php tpl_indexerWebBug()?> | + | |
- | </code> | + | |
- | という行で呼び出している。画面上は1 Pixelの画像だが、これを表示するたびにindexer.phpが呼び出される仕組み。 | + | |
- | この行を例えば | + | |
- | <code php> | + | |
- | <?php if(time() % 10 == 0) tpl_indexerWebBug();?> | + | |
- | </code> | + | |
- | などと変更する。 | + |