diff options
Diffstat (limited to 'inc/indexer.php')
-rw-r--r-- | inc/indexer.php | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/inc/indexer.php b/inc/indexer.php index 8f0ba7ec6..a167db47f 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -10,7 +10,7 @@ if(!defined('DOKU_INC')) die('meh.'); // Version tag used to force rebuild on upgrade -define('INDEXER_VERSION', 6); +define('INDEXER_VERSION', 8); // 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); @@ -215,7 +215,8 @@ class Doku_Indexer { foreach (array_keys($words) as $wlen) { $word_idx = $this->getIndex('w', $wlen); foreach ($words[$wlen] as $word => $freq) { - $wid = array_search($word, $word_idx); + $word = (string)$word; + $wid = array_search($word, $word_idx, true); if ($wid === false) { $wid = count($word_idx); $word_idx[] = $word; @@ -269,8 +270,9 @@ class Doku_Indexer { // Special handling for titles so the index file is simpler if (array_key_exists('title', $key)) { $value = $key['title']; - if (is_array($value)) + if (is_array($value)) { $value = $value[0]; + } $this->saveIndexKey('title', '', $pid, $value); unset($key['title']); } @@ -296,22 +298,26 @@ class Doku_Indexer { foreach ($values as $val) { $val = (string)$val; if ($val !== "") { - $id = array_search($val, $metawords); + $id = array_search($val, $metawords, true); if ($id === false) { + // didn't find $val, so we'll add it to the end of metawords and create a placeholder in metaidx $id = count($metawords); $metawords[$id] = $val; + $metaidx[$id] = ''; $addwords = true; } // test if value is already in the index - if (isset($val_idx[$id]) && $val_idx[$id] <= 0) + if (isset($val_idx[$id]) && $val_idx[$id] <= 0){ $val_idx[$id] = 0; - else // else add it + } else { // else add it $val_idx[$id] = 1; + } } } - if ($addwords) + if ($addwords) { $this->saveIndex($metaname.'_w', '', $metawords); + } $vals_changed = false; foreach ($val_idx as $id => $action) { if ($action == -1) { @@ -352,13 +358,13 @@ class Doku_Indexer { $pages = $this->getPages(); - $id = array_search($oldpage, $pages); + $id = array_search($oldpage, $pages, true); if ($id === false) { $this->unlock(); return 'page is not in index'; } - $new_id = array_search($newpage, $pages); + $new_id = array_search($newpage, $pages, true); if ($new_id !== false) { // make sure the page is not in the index anymore if ($this->deletePageNoLock($newpage) !== true) { @@ -397,9 +403,9 @@ class Doku_Indexer { // change the relation references index $metavalues = $this->getIndex($key, '_w'); - $oldid = array_search($oldvalue, $metavalues); + $oldid = array_search($oldvalue, $metavalues, true); if ($oldid !== false) { - $newid = array_search($newvalue, $metavalues); + $newid = array_search($newvalue, $metavalues, true); if ($newid !== false) { // free memory unset ($metavalues); @@ -600,7 +606,7 @@ class Doku_Indexer { foreach ($wordlist as $i => $word) { if ((!is_numeric($word) && strlen($word) < IDX_MINWORDLENGTH) - || array_search($word, $stopwords) !== false) + || array_search($word, $stopwords, true) !== false) unset($wordlist[$i]); } return array_values($wordlist); @@ -771,7 +777,7 @@ class Doku_Indexer { foreach(array_keys(preg_grep('/'.$re.'/', $words)) as $i) $value_ids[$i][] = $val; } else { - if (($i = array_search($val, $words)) !== false) + if (($i = array_search($val, $words, true)) !== false) $value_ids[$i][] = $val; } } @@ -874,7 +880,7 @@ class Doku_Indexer { // handle exact search if (isset($tokenlength[$ixlen])) { foreach ($tokenlength[$ixlen] as $xword) { - $wid = array_search($xword, $word_idx); + $wid = array_search($xword, $word_idx, true); if ($wid !== false) { $wids[$ixlen][] = $wid; foreach ($tokens[$xword] as $w) @@ -1017,8 +1023,9 @@ class Doku_Indexer { return false; } } - if ($conf['dperm']) + if (!empty($conf['dperm'])) { chmod($lock, $conf['dperm']); + } return $status; } @@ -1152,7 +1159,7 @@ class Doku_Indexer { */ protected function addIndexKey($idx, $suffix, $value) { $index = $this->getIndex($idx, $suffix); - $id = array_search($value, $index); + $id = array_search($value, $index, true); if ($id === false) { $id = count($index); $index[$id] = $value; @@ -1212,14 +1219,16 @@ class Doku_Indexer { */ protected function updateTuple($line, $id, $count) { $newLine = $line; - if ($newLine !== '') + if ($newLine !== ''){ $newLine = preg_replace('/(^|:)'.preg_quote($id,'/').'\*\d*/', '', $newLine); + } $newLine = trim($newLine, ':'); if ($count) { - if (strlen($newLine) > 0) + if (strlen($newLine) > 0) { return "$id*$count:".$newLine; - else + } else { return "$id*$count".$newLine; + } } return $newLine; } |