summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2008-12-26 19:34:03 +0100
committerAndreas Gohr <andi@splitbrain.org>2008-12-26 19:34:03 +0100
commitdd35e9c92ae491b46007c86931b8b4d2e78a95d3 (patch)
tree0c6f3f50993fe1bc4b7c666f76469bd29ca74af8
parent443d207b937495af46f088d883836ad9094bccdd (diff)
downloadrpg-dd35e9c92ae491b46007c86931b8b4d2e78a95d3.tar.gz
rpg-dd35e9c92ae491b46007c86931b8b4d2e78a95d3.tar.bz2
minor optimizations in the fulltext indexing methods
darcs-hash:20081226183403-7ad00-1a4d08ab0f674eb3dcda131dd49ddaeb27129ad6.gz
-rw-r--r--inc/indexer.php29
1 files changed, 23 insertions, 6 deletions
diff --git a/inc/indexer.php b/inc/indexer.php
index 2d019dc77..ca5f552f2 100644
--- a/inc/indexer.php
+++ b/inc/indexer.php
@@ -80,6 +80,21 @@ function idx_saveIndex($pre, $wlen, &$idx){
}
/**
+ * Append a given line to an index file.
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function idx_appendIndex($pre, $wlen, $line){
+ global $conf;
+ $fn = $conf['indexdir'].'/'.$pre.$wlen;
+ $fh = @fopen($fn.'.idx','a');
+ if(!$fh) return false;
+ fwrite($fh,$line);
+ fclose($fh);
+ return true;
+}
+
+/**
* Read the list of words in an index (if it exists).
*
* @author Tom N Harris <tnharris@whoopdedo.org>
@@ -204,7 +219,7 @@ function idx_getPageWords($page){
unset($evt);
list($page,$body) = $data;
-
+
$body = strtr($body, "\r\n\t", ' ');
$tokens = explode(' ', $body);
$tokens = array_count_values($tokens); // count the frequency of each token
@@ -284,14 +299,14 @@ function idx_addPage($page){
// get page id (this is the linenumber in page.idx)
$pid = array_search("$page\n",$page_idx);
if(!is_int($pid)){
- $page_idx[] = "$page\n";
$pid = count($page_idx)-1;
// page was new - write back
- if (!idx_saveIndex('page','',$page_idx)){
+ if (!idx_appendIndex('page','',"$page\n")){
trigger_error("Failed to write page index", E_USER_ERROR);
return false;
}
}
+ unset($page_idx); // free memory
$pagewords = array();
// get word usage in page
@@ -320,7 +335,7 @@ function idx_addPage($page){
}
}
}
-
+
// Remove obsolete index entries
$pageword_idx = trim(idx_getIndexLine('pageword','',$pid));
if ($pageword_idx !== '') {
@@ -648,13 +663,15 @@ function idx_upgradePageWords(){
$page_idx = idx_getIndex('page','');
if (empty($page_idx)) return;
$pagewords = array();
- for ($n=0;$n<count($page_idx);$n++) $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);
- for ($wid=0;$wid<count($lines);$wid++) {
+ $len = count($lines);
+ for ($wid=0;$wid<$len;$wid++) {
$wkey = "$wlen*$wid";
foreach (explode(':',trim($lines[$wid])) as $part) {
if($part == '') continue;