diff options
author | TNHarris <telliamed@fastmail.us> | 2006-11-12 20:49:00 +0100 |
---|---|---|
committer | TNHarris <telliamed@fastmail.us> | 2006-11-12 20:49:00 +0100 |
commit | 579b0f7e8d80287b11fd441dfa68d15e9d4bb74c (patch) | |
tree | c2ba569b8493a7b724df57c90dcd07a89890c8a3 /lib/plugins | |
parent | c64b282c718d5e728c9a6555cf3e29ebd1bf4524 (diff) | |
download | rpg-579b0f7e8d80287b11fd441dfa68d15e9d4bb74c.tar.gz rpg-579b0f7e8d80287b11fd441dfa68d15e9d4bb74c.tar.bz2 |
Word-Length Indexer
A modification to the indexer that sorts words based on length. This should make
searching a little bit more efficient. After the patch is applied, your old index
will be automatically converted to the new format (when you visit a page). The
new index format is:
1. Index files are stored in savedir/index
2. Word lists are stored as wlen.idx. This used to be word.idx.
3. Word indexes are stored as ilen.idx. This used to be index.idx.
4. The page list, page.idx, is simply copied to the new location.
Any plugins you have, such as the blog plugin, that read the index files need to
be updated.
darcs-hash:20061112194900-2b9f0-a975498ccf0a1d39c6df73b79bcd028d5e81c389.gz
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/importoldindex/action.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/plugins/importoldindex/action.php b/lib/plugins/importoldindex/action.php new file mode 100644 index 000000000..26b37664c --- /dev/null +++ b/lib/plugins/importoldindex/action.php @@ -0,0 +1,58 @@ +<?php +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'action.php'); + +class action_plugin_importoldindex extends DokuWiki_Action_Plugin { + + function getInfo(){ + return array( + 'author' => 'Tom N Harris', + 'email' => 'tnharris@whoopdedo.org', + 'date' => '2006-11-09', + 'name' => 'Import Old Index', + 'desc' => 'Moves old index files to a new location, sorted by string length.', + 'url' => 'http://whoopdedo.org/doku/wiki' + ); + } + + function register(&$controller) { + $controller->register_hook('TEMPORARY_INDEX_UPGRADE_EVENT', 'BEFORE', $this, 'run_import'); + } + + function run_import(&$event, $args) { + global $conf; + + touch($conf['indexdir'].'/index_importing'); // changelog importing lock + // load old index + $word_idx = file($conf['cachedir'].'/word.idx'); + $idx = file($conf['cachedir'].'/index.idx'); + $words = array(); + for ($lno=0;$lno<count($word_idx);$lno++){ + $wlen = strlen($word_idx[$lno])-1; + //if($wlen<3) continue; + if(!isset($words[$wlen])) $words[$wlen] = array(); + $words[$wlen][] = $lno; + } + + foreach (array_keys($words) as $wlen) { + $new_words = array(); + $new_idx = array(); + foreach ($words[$wlen] as $lno) { + $new_words[] = $word_idx[$lno]; + $new_idx[] = $idx[$lno]; + } + io_saveFile($conf['indexdir']."/w$wlen.idx", implode('', $new_words)); + io_saveFile($conf['indexdir']."/i$wlen.idx", implode('', $new_idx)); + } + + @copy($conf['cachedir'].'/page.idx', $conf['indexdir'].'/page.idx'); + if($conf['fperm']) chmod($conf['indexdir'].'/page.idx', $conf['fperm']); + unlink($conf['indexdir'].'/index_importing'); // changelog importing unlock + plugin_disable('importoldindex'); // only needs to run once + } + +} + |