差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
dokuwiki:localize [2005/12/05 16:39] osamudokuwiki:localize [2007/07/31 15:36] (現在) osamu
行 1: 行 1:
 ====== DokuWikiの日本語対応 ====== ====== DokuWikiの日本語対応 ======
-[[doku>wiki:install|DokuWikiのインストールマニュアル]]([[wiki:install|日本語版―作業中]])にしたがって普通にインストール、設定ファイルの''conf/dokuwiki.php''''conf/local.php''の中に+[[doku>wiki:install|DokuWikiのインストールマニュアル]]([[doku>wiki:ja:install|日本語版]])にしたがって普通にインストール。インストール画面で日本語を選択すれば自動的に設定ファイルの''conf/local.php''の中に
 <code php> <code php>
 $conf['lang'] = 'ja';  $conf['lang'] = 'ja'; 
 </code> </code>
-と記述すると、ユーザーインターフェースの文字列などは日本語になる。+と記述されて、ユーザーインターフェースの文字列などは日本語になる。
 機能面での日本語対応を強化するために、次の改造を加える。 機能面での日本語対応を強化するために、次の改造を加える。
  
行 72: 行 72:
 ^D</code> ^D</code>
 のように、入力した文字が分かち書きされて表示されればOK。 のように、入力した文字が分かち書きされて表示されればOK。
 +
 +
 +
 +
  
  
行 92: 行 96:
 function idx_getPageWords($page)の function idx_getPageWords($page)の
 <code php> <code php>
-      $body   = rawWiki($page);+      list($page,$body= $data;
 </code> </code>
-後ろ+と 
 +<code php> 
 +    $body   = strtr($body, "\r\n\t",  '); 
 +</code> 
 +
 <code php> <code php>
      if(function_exists(proc_open) && defined('PRE_TOKENIZER')) {      if(function_exists(proc_open) && defined('PRE_TOKENIZER')) {
行 104: 行 112:
         $process = proc_open(PRE_TOKENIZER, $dspec, $pipes);         $process = proc_open(PRE_TOKENIZER, $dspec, $pipes);
         if(is_resource($process)) {         if(is_resource($process)) {
 +            stream_set_blocking($pipes[0], FALSE);
 +            stream_set_blocking($pipes[1], FALSE);
             fwrite($pipes[0], $body . "\n");             fwrite($pipes[0], $body . "\n");
             fclose($pipes[0]);             fclose($pipes[0]);
 +
 +            $body = '';
 +            while(!feof($pipes[1])) {
 +                $body .= fgets($pipes[1], 32768);
 +            }
 +            fclose($pipes[1]);
 +            proc_close($process);
         }         }
-        $body = ''; 
-        while(!feof($pipes[1])) { 
-            $body .= fgets($pipes[1], 32768); 
-        } 
-        fclose($pipes[1]); 
-        proc_close($process); 
     }     }
 </code> </code>
行 131: 行 142:
         $process = proc_open(PRE_TOKENIZER, $dspec, $pipes);         $process = proc_open(PRE_TOKENIZER, $dspec, $pipes);
         if(is_resource($process)) {         if(is_resource($process)) {
 +            stream_set_blocking($pipes[0], FALSE);
 +            stream_set_blocking($pipes[1], FALSE);
             fwrite($pipes[0], $string . "\n");             fwrite($pipes[0], $string . "\n");
             fclose($pipes[0]);             fclose($pipes[0]);
 +            $string = '';
 +            while(!feof($pipes[1])) {
 +                $string .= fgets($pipes[1], 32768);
 +            }
 +            fclose($pipes[1]);
 +            proc_close($process);
         }         }
-        $string = ''; 
-        while(!feof($pipes[1])) { 
-            $string .= fgets($pipes[1], 32768); 
-        } 
-        fclose($pipes[1]); 
-        proc_close($process); 
     }     }
 </code> </code>
 を追加。 を追加。
  
 +DokuWikiの最近のバージョンでは、日本語を含むアジア圏の文字を1文字1単語とみなして検索する修正が入っているが、これを使うと例えば「文字を探す」で検索すると「文」「字」「を」「探」「す」のすべての文字が検索結果でハイライトされたりして具合がよくない。上記の修正を加えたときは、idx_tokenizer($string,&$stopwords)関数にある
 +<code php> 
 +            $asia = @preg_replace('/('.IDX_ASIAN.')/u','\1 ',$word);
 +            if(!is_null($asia)) $word = $asia; //recover from regexp failure
 +</code>
 +という2行をコメントアウトする。
 +また、indexer.phpにwordlen()という関数があるが、これも同じくアジア圏の文字は1文字1単語とみなす処理が入っているので
 +<code php>
 +function wordlen($w){
 +    // $l = strlen($w);
  
 +    $l = utf8_strlen($w);
  
 +    //// If left alone, all chinese "words" will get put into w3.idx
 +    //// So the "length" of a "word" is faked
 +    //if(preg_match('/'.IDX_ASIAN2.'/u',$w))
 +    //    $l += ord($w) - 0xE1;  // Lead bytes from 0xE2-0xEF
  
 +    return $l;
 +}
 +</code>
 +と変更。
 +
 +それから、同じくindexer.php の idx_getIndexWordsSorted() 関数の中に、
 +<code php>
 +        if ($wlen < 3 && $wild == 0 && !is_numeric($xword)) continue;
 +</code>
 +という部分があるが、このままだと3文字より短い単語を検索できない。英語などではそれでもよいのだが、日本語の場合1~2文字の単語も検索できないと困るので、これを
 +<code php>
 +        if (preg_match('/[^0-9A-Za-z]/u', $string) && $wlen < 3 && $wild == 0 && !is_numeric($xword)) continue;
 +</code>
 +と書き換える。
 +
 +
 +//2005-12-8 - Mecabのプロセスがハングアップして残ってしまうのを避けるために''stream_set_blocking()''を追加//\\ 
 +//2007-7-29 - DokuWikiの最近のバージョンにあわせて、修正箇所の説明を変更//
  
  
行 165: 行 211:
 http://bugs.splitbrain.org/?do=details&id=653 にバグ報告済み。 http://bugs.splitbrain.org/?do=details&id=653 にバグ報告済み。
  
- +// 追記: この不具合は、現在配布されていージンでは修正されてす。//
- +
- +
- +
-==== 負荷の軽減 ==== +
-FIXME 検索の機能はれで働くようになるのだが、ヒット数の多いサイト、このままではサーバーの負荷がかなり重くなるはず。 +
-DokuWikiでは、ページを誰かが表示すたびに、そのページの検索イデックスを作り直す仕組みになっている。もともと全文検索のインデックス更新は軽い仕事では上に、この改造で毎回Mecabを動かことになって、負荷が大きくなっている。 +
-対策検討中 +
dokuwiki/localize.1133768344.txt.gz · 最終更新: 2007/07/23 16:50 (外部編集)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0