summaryrefslogtreecommitdiff
path: root/inc/indexer.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/indexer.php')
-rw-r--r--inc/indexer.php92
1 files changed, 68 insertions, 24 deletions
diff --git a/inc/indexer.php b/inc/indexer.php
index 14af579bb..01ba76b08 100644
--- a/inc/indexer.php
+++ b/inc/indexer.php
@@ -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 @@ function idx_addPage($page){
}
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);
@@ -414,40 +413,85 @@ function idx_updateIndexLine($line,$pid,$count){
}
/**
+ * 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.
*
* 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;
+ if (is_array($filter)){
+ // 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;
+ } else {
+ $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;
}