ラベル DokiWiki の投稿を表示しています。 すべての投稿を表示
ラベル DokiWiki の投稿を表示しています。 すべての投稿を表示

2011年3月3日木曜日

DokuWiki-2010-11-07a その2

inc/indexer.php

こんな感じに変更。

でぃふ


--- indexer.php.org 2011-03-03 16:42:26.000000000 +0900
+++ indexer.php.110303171410 2011-03-03 17:14:10.000000000 +0900
@@ -42,6 +42,8 @@
']?');
define('IDX_ASIAN', '(?:'.IDX_ASIAN1.'|'.IDX_ASIAN2.'|'.IDX_ASIAN3.')');

+define('PRE_TOKENIZER', '/usr/bin/mecab -O wakati');
+

/**
* Measure the length of a string.
* Differs from strlen in handling of asian characters.
@@ -49,11 +51,15 @@
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
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;
}

@@ -217,6 +223,28 @@

list($page,$body) = $data;

+ if(function_exists(proc_open) && defined('PRE_TOKENIZER')) {

+ $dspec = array(
+ 0 => array("pipe", "r"),
+ 1 => array("pipe", "w"),
+ 2 => array("file", "/dev/null", "w")
+ );
+ $process = proc_open(PRE_TOKENIZER, $dspec, $pipes);

+ if(is_resource($process)) {
+ stream_set_blocking($pipes[0], FALSE);
+ stream_set_blocking($pipes[1], FALSE);
+ fwrite($pipes[0], $body . "\n");
+ fclose($pipes[0]);
+
+ $body = '';
+ while(!feof($pipes[1])) {
+ $body .= fgets($pipes[1], 32768);

+ }
+ fclose($pipes[1]);
+ proc_close($process);
+ }
+ }
+
$body = strtr($body, "\r\n\t", ' ');
$tokens = explode(' ', $body);
$tokens = array_count_values($tokens); // count the frequency of each token
@@ -533,7 +561,7 @@
$wild |= 2;
$wlen -= 1;
}

- if ($wlen < IDX_MINWORDLENGTH && $wild == 0 && !is_numeric($xword)) continue;
+ if (preg_match('/[^0-9A-Za-z]/u', $string) && $wlen < IDX_MINWORDLENGTH && $wild == 0 &
& !is_numeric($xword)) continue;
if(!isset($tokens[$xword])){
$tokenlength[$wlen][] = $xword;
}

@@ -676,12 +704,36 @@
*/
function idx_tokenizer($string,&$stopwords,$wc=false){
$words = array();
+
+ if(function_exists(proc_open) && defined('PRE_TOKENIZER')) {
+ $dspec = array(
+ 0 => array("pipe", "r"),

+ 1 => array("pipe", "w"),
+ 2 => array("file", "/dev/null", "w")
+ );
+ $process = proc_open(PRE_TOKENIZER, $dspec, $pipes);
+ if(is_resource($process)) {
+ stream_set_blocking($pipes[0], FALSE);
+ stream_set_blocking($pipes[1], FALSE);

+ fwrite($pipes[0], $string . "\n");
+ fclose($pipes[0]);
+ $string = '';
+ while(!feof($pipes[1])) {
+ $string .= fgets($pipes[1], 32768);
+ }
+ fclose($pipes[1]);
+ proc_close($process);
+ }

+ }
+
$wc = ($wc) ? '' : $wc = '\*';

if(preg_match('/[^0-9A-Za-z]/u', $string)){
+ /*
// handle asian chars as single words (may fail on older PHP version)
$asia = @preg_replace('/('.IDX_ASIAN.')/u',' \1 ',$string);
if(!is_null($asia)) $string = $asia; //recover from regexp failure
+ */

$arr = explode(' ', utf8_stripspecials($string,' ','\._\-:'.$wc));
foreach ($arr as $w) {

DokuWiki-2010-11-07a その1

ことのおこり

ひさしぶりに管理者でDokuWikiにログインしたら上のほうがうるさいの。

ぐぐる…

DokuWiki はぐぐっても情報ないんだよね…。

ちょうさ

うちのDokuWikiは ここを参考に MeCab 入れて,inc/indexer.php に手を加えている。indexer.php が変わると,ただコピペしているだけの身としては手が出なくなる…。

ええと,

  • idx_listIndexLengths()
    が増えた。
  • idx_indexLengths(&$filter)
    idx_listIndexLengths()
    を使って書き換えられた。
  • idx_upgradePageWords()
    がなくなった。

かな?これならいけそう??

でぃふ

--- E:/dokuwiki/dokuwiki-2009-12-25c/dokuwiki-2009-12-25/inc/indexer.php    Sun Jan 17 19:35:46 2010
+++ E:/dokuwiki/dokuwiki-2010-11-07a/inc/indexer.php    Mon Jan 17 03:04:09 2011
@@ -1,15 +1,12 @@
<?php /** - * Common DokuWiki functions + * Functions to create the fulltext search index * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ if(!defined('DOKU_INC')) die('meh.'); -require_once(DOKU_INC.'inc/io.php'); -require_once(DOKU_INC.'inc/utf8.php'); -require_once(DOKU_INC.'inc/parserutils.php'); // set the minimum token length to use in the index (note, this doesn't apply to numeric tokens) if (!defined('IDX_MINWORDLENGTH')) define('IDX_MINWORDLENGTH',2); @@ -308,6 +305,8 @@ } unset($page_idx); // free memory + idx_saveIndexLine('title', '', $pid, p_get_first_heading($page, false)); + $pagewords = array(); // get word usage in page $words = idx_getPageWords($page); @@ -413,7 +412,58 @@ return join(':',$updated)."\n"; } +/** + * Get the list of lenghts indexed in the wiki + * + * Read the index directory or a cache file and returns + * a sorted array of lengths of the words used in the wiki. + * + * @author YoBoY <yoboy.leguesh@gmail.com> + */ +function idx_listIndexLengths() { + global $conf; + // testing what we have to do, create a cache file or not. + if ($conf['readdircache'] == 0) { + $docache = false; + } else { + clearstatcache(); + if (@file_exists($conf['indexdir'].'/lengths.idx') and (time() < @filemtime($conf['indexdir'].'/lengths.idx') + $conf['readdircache'])) { + if (($lengths = @file($conf['indexdir'].'/lengths.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ) !== false) { + $idx = array(); + foreach ( $lengths as $length) { + $idx[] = (int)$length; + } + return $idx; + } + } + $docache = true; + } + if ($conf['readdircache'] == 0 or $docache ) { + $dir = @opendir($conf['indexdir']); + if($dir===false) + return array(); + $idx[] = array(); + while (($f = readdir($dir)) !== false) { + if (substr($f,0,1) == 'i' && substr($f,-4) == '.idx'){ + $i = substr($f,1,-4); + if (is_numeric($i)) + $idx[] = (int)$i; + } + } + closedir($dir); + sort($idx); + // we save this in a file. + if ($docache === true) { + $handle = @fopen($conf['indexdir'].'/lengths.idx','w'); + @fwrite($handle, implode("\n",$idx)); + @fclose($handle); + } + return $idx; + } + + return array(); +} /** * Get the word lengths that have been indexed. @@ -421,35 +471,27 @@ * Reads the index directory and returns an array of lengths * that there are indices for. * - * @author Tom N Harris <tnharris@whoopdedo.org> + * @author YoBoY <yoboy.leguesh@gmail.com> */ function idx_indexLengths(&$filter){ global $conf; - $dir = @opendir($conf['indexdir']); - if($dir===false) - return array(); $idx = array(); if(is_array($filter)){ - while (($f = readdir($dir)) !== false) { - if (substr($f,0,1) == 'i' && substr($f,-4) == '.idx'){ - $i = substr($f,1,-4); - if (is_numeric($i) && isset($filter[(int)$i])) - $idx[] = (int)$i; + // testing if index files exists only + foreach ($filter as $key => $value) { + if (@file_exists($conf['indexdir']."/i$key.idx")) { + $idx[] = $key; } } }else{ - // Exact match first. - if(@file_exists($conf['indexdir']."/i$filter.idx")) - $idx[] = $filter; - while (($f = readdir($dir)) !== false) { - if (substr($f,0,1) == 'i' && substr($f,-4) == '.idx'){ - $i = substr($f,1,-4); - if (is_numeric($i) && $i > $filter) - $idx[] = (int)$i; + $lengths = idx_listIndexLengths(); + foreach ( $lengths as $key => $length) { + // we keep all the values equal or superior + if ((int)$length >= (int)$filter) { + $idx[] = $length; } } } - closedir($dir); return $idx; } @@ -657,51 +699,6 @@ } return $words; -} - -/** - * Create a pagewords index from the existing index. - * - * @author Tom N Harris <tnharris@whoopdedo.org> - */ -function idx_upgradePageWords(){ - global $conf; - $page_idx = idx_getIndex('page',''); - if (empty($page_idx)) return; - $pagewords = array(); - $len = count($page_idx); - for ($n=0;$n<$len;$n++){ - $pagewords[] = array(); - } - unset($page_idx); - - $n=0; - foreach (idx_indexLengths($n) as $wlen) { - $lines = idx_getIndex('i',$wlen); - $len = count($lines); - for ($wid=0;$wid<$len;$wid++) { - $wkey = "$wlen*$wid"; - foreach (explode(':',trim($lines[$wid])) as $part) { - if($part == '') continue; - list($doc,$cnt) = explode('*',$part); - $pagewords[(int)$doc][] = $wkey; - } - } - } - - $fn = $conf['indexdir'].'/pageword'; - $fh = @fopen($fn.'.tmp','w'); - if (!$fh){ - trigger_error("Failed to write word index", E_USER_ERROR); - return false; - } - foreach ($pagewords as $line){ - fwrite($fh, join(':',$line)."\n"); - } - fclose($fh); - if($conf['fperm']) chmod($fn.'.tmp', $conf['fperm']); - io_rename($fn.'.tmp', $fn.'.idx'); - return true; } //Setup VIM: ex: et ts=4 enc=utf-8 :

つづく

2010年8月9日月曜日

DokuWiki-2009-12-25c その3

あっぷでーと

件のメッセージはconf/msgが更新されれば変わるはず……。かわらへん。なんで?

お使いの DokuWiki をアップグレードして conf/msg ファイル内の数字が大きくなった場合でも、なおアップデートのお知らせが表示され続けることがあります。これは DokuWiki のキャッシュによるものです。DokuWiki は取得したアップデートのお知らせをキャッシュしますが、お知らせの再取得は、前回の取得から 1 日経過した場合とキャッシュの更新日時よりも conf/msg ファイルの更新日時のほうが新しい場合だけしか行われない仕組みとなっています。古いアップデートのお知らせを表示させなくするには、単純に 1 日待つか、conf/msg ファイルの更新日時を touch コマンド1)などで変更するか、もしくは data/cache/messages.txt ファイルを削除するようにしてください。
というわけで,ここにちゃんと書いてあった。 data/cache/message.txtを削除したらちゃんと消えました。

DokuWiki-2009-12-25c その1

ことのおこり

これがそろそろうざったいのでDokuWikiをバージョンアップしようかなと思い立つ。

現在使用中はdokuwiki-2009-02-14b。あいだにdokuwiki-2009-12-02ってのがあったらしい。すんなりいけばいいな

indexer.php(2009-02-14mecab対応)

2009-02-14のときに手を入れた部分(02-14bは数ファイルのみの更新だった)

--- indexer.php.org 2009-02-14 21:13:24.000000000 +0900 +++ indexer.php.mod 2009-04-23 16:17:13.000000000 +0900 @@ -45,6 +45,8 @@ ']?'); define('IDX_ASIAN', '(?:'.IDX_ASIAN1.'|'.IDX_ASIAN2.'|'.IDX_ASIAN3.')'); +define('PRE_TOKENIZER', '/usr/bin/mecab -O wakati'); + /** * Measure the length of a string. * Differs from strlen in handling of asian characters. @@ -52,11 +54,16 @@ * @author Tom N Harris <tnharris@whoopdedo.org> */ function wordlen($w){ - $l = strlen($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; } @@ -220,6 +227,28 @@ list($page,$body) = $data; + if(function_exists(proc_open) && defined('PRE_TOKENIZER')) { + $dspec = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("file", "/dev/null", "w") + ); + $process = proc_open(PRE_TOKENIZER, $dspec, $pipes); + if(is_resource($process)) { + stream_set_blocking($pipes[0], FALSE); + stream_set_blocking($pipes[1], FALSE); + fwrite($pipes[0], $body . "\n"); + fclose($pipes[0]); + + $body = ''; + while(!feof($pipes[1])) { + $body .= fgets($pipes[1], 32768); + } + fclose($pipes[1]); + proc_close($process); + } + } + $body = strtr($body, "\r\n\t", ' '); $tokens = explode(' ', $body); $tokens = array_count_values($tokens); // count the frequency of each token @@ -489,7 +518,8 @@ $wild |= 2; $wlen -= 1; } - if ($wlen < IDX_MINWORDLENGTH && $wild == 0 && !is_numeric($xword)) continue; + //if ($wlen < IDX_MINWORDLENGTH && $wild == 0 && !is_numeric($xword)) continue; + if (preg_match('/[^0-9A-Za-z]/u', $string) && $wlen < IDX_MINWORDLENGTH && $wild == 0 && !is_numeric($xword)) continue; if(!isset($tokens[$xword])){ $tokenlength[$wlen][] = $xword; } @@ -628,12 +658,36 @@ */ function idx_tokenizer($string,&$stopwords,$wc=false){ $words = array(); + + if(function_exists(proc_open) && defined('PRE_TOKENIZER')) { + $dspec = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("file", "/dev/null", "w") + ); + $process = proc_open(PRE_TOKENIZER, $dspec, $pipes); + if(is_resource($process)) { + stream_set_blocking($pipes[0], FALSE); + stream_set_blocking($pipes[1], FALSE); + fwrite($pipes[0], $string . "\n"); + fclose($pipes[0]); + $string = ''; + while(!feof($pipes[1])) { + $string .= fgets($pipes[1], 32768); + } + fclose($pipes[1]); + proc_close($process); + } + } + $wc = ($wc) ? '' : $wc = '\*'; if(preg_match('/[^0-9A-Za-z]/u', $string)){ + /* // handle asian chars as single words (may fail on older PHP version) $asia = @preg_replace('/('.IDX_ASIAN.')/u',' \1 ',$string); if(!is_null($asia)) $string = $asia; //recover from regexp failure + */ $arr = explode(' ', utf8_stripspecials($string,' ','\._\-:'.$wc)); foreach ($arr as $w) {

Debianでmecabをaptでインストールすると,/usr/bin/mecabにインストールされるけど,ほかの環境の人はここを変えないと。

つづく