xref: /dokuwiki/inc/indexer.php (revision e24ab4ab794093b0d9ca1095e321b04f9cd956d6)
1<?php
2/**
3 * Functions to create the fulltext search index
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9if(!defined('DOKU_INC')) die('meh.');
10
11// set the minimum token length to use in the index (note, this doesn't apply to numeric tokens)
12if (!defined('IDX_MINWORDLENGTH')) define('IDX_MINWORDLENGTH',2);
13
14// Asian characters are handled as words. The following regexp defines the
15// Unicode-Ranges for Asian characters
16// Ranges taken from http://en.wikipedia.org/wiki/Unicode_block
17// I'm no language expert. If you think some ranges are wrongly chosen or
18// a range is missing, please contact me
19define('IDX_ASIAN1','[\x{0E00}-\x{0E7F}]'); // Thai
20define('IDX_ASIAN2','['.
21                   '\x{2E80}-\x{3040}'.  // CJK -> Hangul
22                   '\x{309D}-\x{30A0}'.
23                   '\x{30FD}-\x{31EF}\x{3200}-\x{D7AF}'.
24                   '\x{F900}-\x{FAFF}'.  // CJK Compatibility Ideographs
25                   '\x{FE30}-\x{FE4F}'.  // CJK Compatibility Forms
26                   "\xF0\xA0\x80\x80-\xF0\xAA\x9B\x9F". // CJK Extension B
27                   "\xF0\xAA\x9C\x80-\xF0\xAB\x9C\xBF". // CJK Extension C
28                   "\xF0\xAB\x9D\x80-\xF0\xAB\xA0\x9F". // CJK Extension D
29                   "\xF0\xAF\xA0\x80-\xF0\xAF\xAB\xBF". // CJK Compatibility Supplement
30                   ']');
31define('IDX_ASIAN3','['.                // Hiragana/Katakana (can be two characters)
32                   '\x{3042}\x{3044}\x{3046}\x{3048}'.
33                   '\x{304A}-\x{3062}\x{3064}-\x{3082}'.
34                   '\x{3084}\x{3086}\x{3088}-\x{308D}'.
35                   '\x{308F}-\x{3094}'.
36                   '\x{30A2}\x{30A4}\x{30A6}\x{30A8}'.
37                   '\x{30AA}-\x{30C2}\x{30C4}-\x{30E2}'.
38                   '\x{30E4}\x{30E6}\x{30E8}-\x{30ED}'.
39                   '\x{30EF}-\x{30F4}\x{30F7}-\x{30FA}'.
40                   ']['.
41                   '\x{3041}\x{3043}\x{3045}\x{3047}\x{3049}'.
42                   '\x{3063}\x{3083}\x{3085}\x{3087}\x{308E}\x{3095}-\x{309C}'.
43                   '\x{30A1}\x{30A3}\x{30A5}\x{30A7}\x{30A9}'.
44                   '\x{30C3}\x{30E3}\x{30E5}\x{30E7}\x{30EE}\x{30F5}\x{30F6}\x{30FB}\x{30FC}'.
45                   '\x{31F0}-\x{31FF}'.
46                   ']?');
47define('IDX_ASIAN', '(?:'.IDX_ASIAN1.'|'.IDX_ASIAN2.'|'.IDX_ASIAN3.')');
48
49/**
50 * Measure the length of a string.
51 * Differs from strlen in handling of asian characters.
52 *
53 * @author Tom N Harris <tnharris@whoopdedo.org>
54 */
55function wordlen($w){
56    $l = strlen($w);
57    // If left alone, all chinese "words" will get put into w3.idx
58    // So the "length" of a "word" is faked
59    if(preg_match('/'.IDX_ASIAN2.'/u',$w))
60        $l += ord($w) - 0xE1;  // Lead bytes from 0xE2-0xEF
61    return $l;
62}
63
64/**
65 * Write a list of strings to an index file.
66 *
67 * @author Tom N Harris <tnharris@whoopdedo.org>
68 */
69function idx_saveIndex($pre, $wlen, &$idx){
70    global $conf;
71    $fn = $conf['indexdir'].'/'.$pre.$wlen;
72    $fh = @fopen($fn.'.tmp','w');
73    if(!$fh) return false;
74    foreach ($idx as $line) {
75        fwrite($fh,$line);
76    }
77    fclose($fh);
78    if(isset($conf['fperm'])) chmod($fn.'.tmp', $conf['fperm']);
79    io_rename($fn.'.tmp', $fn.'.idx');
80    return true;
81}
82
83/**
84 * Append a given line to an index file.
85 *
86 * @author Andreas Gohr <andi@splitbrain.org>
87 */
88function idx_appendIndex($pre, $wlen, $line){
89    global $conf;
90    $fn = $conf['indexdir'].'/'.$pre.$wlen;
91    $fh = @fopen($fn.'.idx','a');
92    if(!$fh) return false;
93    fwrite($fh,$line);
94    fclose($fh);
95    return true;
96}
97
98/**
99 * Read the list of words in an index (if it exists).
100 *
101 * @author Tom N Harris <tnharris@whoopdedo.org>
102 */
103function idx_getIndex($pre, $wlen){
104    global $conf;
105    $fn = $conf['indexdir'].'/'.$pre.$wlen.'.idx';
106    if(!@file_exists($fn)) return array();
107    return file($fn);
108}
109
110/**
111 * Create an empty index file if it doesn't exist yet.
112 *
113 * FIXME: This function isn't currently used. It will probably be removed soon.
114 *
115 * @author Tom N Harris <tnharris@whoopdedo.org>
116 */
117function idx_touchIndex($pre, $wlen){
118    global $conf;
119    $fn = $conf['indexdir'].'/'.$pre.$wlen.'.idx';
120    if(!@file_exists($fn)){
121        touch($fn);
122        if($conf['fperm']) chmod($fn, $conf['fperm']);
123    }
124}
125
126/**
127 * Read a line ending with \n.
128 * Returns false on EOF.
129 *
130 * @author Tom N Harris <tnharris@whoopdedo.org>
131 */
132function _freadline($fh) {
133    if (feof($fh)) return false;
134    $ln = '';
135    while (($buf = fgets($fh,4096)) !== false) {
136        $ln .= $buf;
137        if (substr($buf,-1) == "\n") break;
138    }
139    if ($ln === '') return false;
140    if (substr($ln,-1) != "\n") $ln .= "\n";
141    return $ln;
142}
143
144/**
145 * Write a line to an index file.
146 *
147 * @author Tom N Harris <tnharris@whoopdedo.org>
148 */
149function idx_saveIndexLine($pre, $wlen, $idx, $line){
150    global $conf;
151    if(substr($line,-1) != "\n") $line .= "\n";
152    $fn = $conf['indexdir'].'/'.$pre.$wlen;
153    $fh = @fopen($fn.'.tmp','w');
154    if(!$fh) return false;
155    $ih = @fopen($fn.'.idx','r');
156    if ($ih) {
157        $ln = -1;
158        while (($curline = _freadline($ih)) !== false) {
159            if (++$ln == $idx) {
160                fwrite($fh, $line);
161            } else {
162                fwrite($fh, $curline);
163            }
164        }
165        if ($idx > $ln) {
166            fwrite($fh,$line);
167        }
168        fclose($ih);
169    } else {
170        fwrite($fh,$line);
171    }
172    fclose($fh);
173    if($conf['fperm']) chmod($fn.'.tmp', $conf['fperm']);
174    io_rename($fn.'.tmp', $fn.'.idx');
175    return true;
176}
177
178/**
179 * Read a single line from an index (if it exists).
180 *
181 * @author Tom N Harris <tnharris@whoopdedo.org>
182 */
183function idx_getIndexLine($pre, $wlen, $idx){
184    global $conf;
185    $fn = $conf['indexdir'].'/'.$pre.$wlen.'.idx';
186    if(!@file_exists($fn)) return '';
187    $fh = @fopen($fn,'r');
188    if(!$fh) return '';
189    $ln = -1;
190    while (($line = _freadline($fh)) !== false) {
191        if (++$ln == $idx) break;
192    }
193    fclose($fh);
194    return "$line";
195}
196
197/**
198 * Split a page into words
199 *
200 * Returns an array of word counts, false if an error occurred.
201 * Array is keyed on the word length, then the word index.
202 *
203 * @author Andreas Gohr <andi@splitbrain.org>
204 * @author Christopher Smith <chris@jalakai.co.uk>
205 */
206function idx_getPageWords($page){
207    global $conf;
208    $swfile   = DOKU_INC.'inc/lang/'.$conf['lang'].'/stopwords.txt';
209    if(@file_exists($swfile)){
210        $stopwords = file($swfile);
211    }else{
212        $stopwords = array();
213    }
214
215    $body = '';
216    $data = array($page, $body);
217    $evt = new Doku_Event('INDEXER_PAGE_ADD', $data);
218    if ($evt->advise_before()) $data[1] .= rawWiki($page);
219    $evt->advise_after();
220    unset($evt);
221
222    list($page,$body) = $data;
223
224    $body   = strtr($body, "\r\n\t", '   ');
225    $tokens = explode(' ', $body);
226    $tokens = array_count_values($tokens);   // count the frequency of each token
227
228    // ensure the deaccented or romanised page names of internal links are added to the token array
229    // (this is necessary for the backlink function -- there maybe a better way!)
230    if ($conf['deaccent']) {
231        $links = p_get_metadata($page,'relation references');
232
233        if (!empty($links)) {
234            $tmp = join(' ',array_keys($links));                // make a single string
235            $tmp = strtr($tmp, ':', ' ');                       // replace namespace separator with a space
236            $link_tokens = array_unique(explode(' ', $tmp));    // break into tokens
237
238            foreach ($link_tokens as $link_token) {
239                if (isset($tokens[$link_token])) continue;
240                $tokens[$link_token] = 1;
241            }
242        }
243    }
244
245    $words = array();
246    foreach ($tokens as $word => $count) {
247        $arr = idx_tokenizer($word,$stopwords);
248        $arr = array_count_values($arr);
249        foreach ($arr as $w => $c) {
250            $l = wordlen($w);
251            if(isset($words[$l])){
252                $words[$l][$w] = $c * $count + (isset($words[$l][$w]) ? $words[$l][$w] : 0);
253            }else{
254                $words[$l] = array($w => $c * $count);
255            }
256        }
257    }
258
259    // arrive here with $words = array(wordlen => array(word => frequency))
260
261    $index = array(); //resulting index
262    foreach (array_keys($words) as $wlen){
263        $word_idx = idx_getIndex('w',$wlen);
264        foreach ($words[$wlen] as $word => $freq) {
265            $wid = array_search("$word\n",$word_idx);
266            if(!is_int($wid)){
267                $wid = count($word_idx);
268                $word_idx[] = "$word\n";
269            }
270            if(!isset($index[$wlen]))
271                $index[$wlen] = array();
272            $index[$wlen][$wid] = $freq;
273        }
274
275        // save back word index
276        if(!idx_saveIndex('w',$wlen,$word_idx)){
277            trigger_error("Failed to write word index", E_USER_ERROR);
278            return false;
279        }
280    }
281
282    return $index;
283}
284
285/**
286 * Adds/updates the search for the given page
287 *
288 * This is the core function of the indexer which does most
289 * of the work. This function needs to be called with proper
290 * locking!
291 *
292 * @author Andreas Gohr <andi@splitbrain.org>
293 */
294function idx_addPage($page){
295    global $conf;
296
297    // load known documents
298    $page_idx = idx_getIndex('page','');
299
300    // get page id (this is the linenumber in page.idx)
301    $pid = array_search("$page\n",$page_idx);
302    if(!is_int($pid)){
303        $pid = count($page_idx);
304        // page was new - write back
305        if (!idx_appendIndex('page','',"$page\n")){
306            trigger_error("Failed to write page index", E_USER_ERROR);
307            return false;
308        }
309    }
310    unset($page_idx); // free memory
311
312    idx_saveIndexLine('title', '', $pid, p_get_first_heading($page, true));
313
314    $pagewords = array();
315    // get word usage in page
316    $words = idx_getPageWords($page);
317    if($words === false) return false;
318
319    if(!empty($words)) {
320        foreach(array_keys($words) as $wlen){
321            $index = idx_getIndex('i',$wlen);
322            foreach($words[$wlen] as $wid => $freq){
323                if($wid<count($index)){
324                    $index[$wid] = idx_updateIndexLine($index[$wid],$pid,$freq);
325                }else{
326                    // New words **should** have been added in increasing order
327                    // starting with the first unassigned index.
328                    // If someone can show how this isn't true, then I'll need to sort
329                    // or do something special.
330                    $index[$wid] = idx_updateIndexLine('',$pid,$freq);
331                }
332                $pagewords[] = "$wlen*$wid";
333            }
334            // save back word index
335            if(!idx_saveIndex('i',$wlen,$index)){
336                trigger_error("Failed to write index", E_USER_ERROR);
337                return false;
338            }
339        }
340    }
341
342    // Remove obsolete index entries
343    $pageword_idx = trim(idx_getIndexLine('pageword','',$pid));
344    if ($pageword_idx !== '') {
345        $oldwords = explode(':',$pageword_idx);
346        $delwords = array_diff($oldwords, $pagewords);
347        $upwords = array();
348        foreach ($delwords as $word) {
349            if($word=='') continue;
350            list($wlen,$wid) = explode('*',$word);
351            $wid = (int)$wid;
352            $upwords[$wlen][] = $wid;
353        }
354        foreach ($upwords as $wlen => $widx) {
355            $index = idx_getIndex('i',$wlen);
356            foreach ($widx as $wid) {
357                $index[$wid] = idx_updateIndexLine($index[$wid],$pid,0);
358            }
359            idx_saveIndex('i',$wlen,$index);
360        }
361    }
362    // Save the reverse index
363    $pageword_idx = join(':',$pagewords)."\n";
364    if(!idx_saveIndexLine('pageword','',$pid,$pageword_idx)){
365        trigger_error("Failed to write word index", E_USER_ERROR);
366        return false;
367    }
368
369    return true;
370}
371
372/**
373 * Write a new index line to the filehandle
374 *
375 * This function writes an line for the index file to the
376 * given filehandle. It removes the given document from
377 * the given line and readds it when $count is >0.
378 *
379 * @deprecated - see idx_updateIndexLine
380 * @author Andreas Gohr <andi@splitbrain.org>
381 */
382function idx_writeIndexLine($fh,$line,$pid,$count){
383    fwrite($fh,idx_updateIndexLine($line,$pid,$count));
384}
385
386/**
387 * Modify an index line with new information
388 *
389 * This returns a line of the index. It removes the
390 * given document from the line and readds it if
391 * $count is >0.
392 *
393 * @author Tom N Harris <tnharris@whoopdedo.org>
394 * @author Andreas Gohr <andi@splitbrain.org>
395 */
396function idx_updateIndexLine($line,$pid,$count){
397    $line = trim($line);
398    $updated = array();
399    if($line != ''){
400        $parts = explode(':',$line);
401        // remove doc from given line
402        foreach($parts as $part){
403            if($part == '') continue;
404            list($doc,$cnt) = explode('*',$part);
405            if($doc != $pid){
406                $updated[] = $part;
407            }
408        }
409    }
410
411    // add doc
412    if ($count){
413        $updated[] = "$pid*$count";
414    }
415
416    return join(':',$updated)."\n";
417}
418
419/**
420 * Get the list of lenghts indexed in the wiki
421 *
422 * Read the index directory or a cache file and returns
423 * a sorted array of lengths of the words used in the wiki.
424 *
425 * @author YoBoY <yoboy.leguesh@gmail.com>
426 */
427function idx_listIndexLengths() {
428    global $conf;
429    // testing what we have to do, create a cache file or not.
430    if ($conf['readdircache'] == 0) {
431        $docache = false;
432    } else {
433        clearstatcache();
434        if (@file_exists($conf['indexdir'].'/lengths.idx') and (time() < @filemtime($conf['indexdir'].'/lengths.idx') + $conf['readdircache'])) {
435            if (($lengths = @file($conf['indexdir'].'/lengths.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ) !== false) {
436                $idx = array();
437                foreach ( $lengths as $length) {
438                    $idx[] = (int)$length;
439                }
440                return $idx;
441            }
442        }
443        $docache = true;
444    }
445
446    if ($conf['readdircache'] == 0 or $docache ) {
447        $dir = @opendir($conf['indexdir']);
448        if($dir===false)
449            return array();
450        $idx[] = array();
451        while (($f = readdir($dir)) !== false) {
452            if (substr($f,0,1) == 'i' && substr($f,-4) == '.idx'){
453                $i = substr($f,1,-4);
454                if (is_numeric($i))
455                    $idx[] = (int)$i;
456            }
457        }
458        closedir($dir);
459        sort($idx);
460        // we save this in a file.
461        if ($docache === true) {
462            $handle = @fopen($conf['indexdir'].'/lengths.idx','w');
463            @fwrite($handle, implode("\n",$idx));
464            @fclose($handle);
465        }
466        return $idx;
467    }
468
469    return array();
470}
471
472/**
473 * Get the word lengths that have been indexed.
474 *
475 * Reads the index directory and returns an array of lengths
476 * that there are indices for.
477 *
478 * @author YoBoY <yoboy.leguesh@gmail.com>
479 */
480function idx_indexLengths(&$filter){
481    global $conf;
482    $idx = array();
483    if (is_array($filter)){
484        // testing if index files exists only
485        foreach ($filter as $key => $value) {
486            if (@file_exists($conf['indexdir']."/i$key.idx")) {
487                $idx[] = $key;
488            }
489        }
490    } else {
491        $lengths = idx_listIndexLengths();
492        foreach ( $lengths as $key => $length) {
493            // we keep all the values equal or superior
494            if ((int)$length >= (int)$filter) {
495                $idx[] = $length;
496            }
497        }
498    }
499    return $idx;
500}
501
502/**
503 * Find the the index number of each search term.
504 *
505 * This will group together words that appear in the same index.
506 * So it should perform better, because it only opens each index once.
507 * Actually, it's not that great. (in my experience) Probably because of the disk cache.
508 * And the sorted function does more work, making it slightly slower in some cases.
509 *
510 * @param array    $words   The query terms. Words should only contain valid characters,
511 *                          with a '*' at either the beginning or end of the word (or both)
512 * @param arrayref $result  Set to word => array("length*id" ...), use this to merge the
513 *                          index locations with the appropriate query term.
514 * @return array            Set to length => array(id ...)
515 *
516 * @author Tom N Harris <tnharris@whoopdedo.org>
517 */
518function idx_getIndexWordsSorted($words,&$result){
519    // parse and sort tokens
520    $tokens = array();
521    $tokenlength = array();
522    $tokenwild = array();
523    foreach($words as $word){
524        $result[$word] = array();
525        $wild = 0;
526        $xword = $word;
527        $wlen = wordlen($word);
528
529        // check for wildcards
530        if(substr($xword,0,1) == '*'){
531            $xword = substr($xword,1);
532            $wild |= 1;
533            $wlen -= 1;
534        }
535        if(substr($xword,-1,1) == '*'){
536            $xword = substr($xword,0,-1);
537            $wild |= 2;
538            $wlen -= 1;
539        }
540        if ($wlen < IDX_MINWORDLENGTH && $wild == 0 && !is_numeric($xword)) continue;
541        if(!isset($tokens[$xword])){
542            $tokenlength[$wlen][] = $xword;
543        }
544        if($wild){
545            $ptn = preg_quote($xword,'/');
546            if(($wild&1) == 0) $ptn = '^'.$ptn;
547            if(($wild&2) == 0) $ptn = $ptn.'$';
548            $tokens[$xword][] = array($word, '/'.$ptn.'/');
549            if(!isset($tokenwild[$xword])) $tokenwild[$xword] = $wlen;
550        }else
551            $tokens[$xword][] = array($word, null);
552    }
553    asort($tokenwild);
554    // $tokens = array( base word => array( [ query word , grep pattern ] ... ) ... )
555    // $tokenlength = array( base word length => base word ... )
556    // $tokenwild = array( base word => base word length ... )
557
558    $length_filter = empty($tokenwild) ? $tokenlength : min(array_keys($tokenlength));
559    $indexes_known = idx_indexLengths($length_filter);
560    if(!empty($tokenwild)) sort($indexes_known);
561    // get word IDs
562    $wids = array();
563    foreach($indexes_known as $ixlen){
564        $word_idx = idx_getIndex('w',$ixlen);
565        // handle exact search
566        if(isset($tokenlength[$ixlen])){
567            foreach($tokenlength[$ixlen] as $xword){
568                $wid = array_search("$xword\n",$word_idx);
569                if(is_int($wid)){
570                    $wids[$ixlen][] = $wid;
571                    foreach($tokens[$xword] as $w)
572                        $result[$w[0]][] = "$ixlen*$wid";
573                }
574            }
575        }
576        // handle wildcard search
577        foreach($tokenwild as $xword => $wlen){
578            if($wlen >= $ixlen) break;
579            foreach($tokens[$xword] as $w){
580                if(is_null($w[1])) continue;
581                foreach(array_keys(preg_grep($w[1],$word_idx)) as $wid){
582                    $wids[$ixlen][] = $wid;
583                    $result[$w[0]][] = "$ixlen*$wid";
584                }
585            }
586        }
587    }
588    return $wids;
589}
590
591/**
592 * Lookup words in index
593 *
594 * Takes an array of word and will return a list of matching
595 * documents for each one.
596 *
597 * Important: No ACL checking is done here! All results are
598 *            returned, regardless of permissions
599 *
600 * @author Andreas Gohr <andi@splitbrain.org>
601 */
602function idx_lookup($words){
603    global $conf;
604
605    $result = array();
606
607    $wids = idx_getIndexWordsSorted($words, $result);
608    if(empty($wids)) return array();
609
610    // load known words and documents
611    $page_idx = idx_getIndex('page','');
612
613    $docs = array();                          // hold docs found
614    foreach(array_keys($wids) as $wlen){
615        $wids[$wlen] = array_unique($wids[$wlen]);
616        $index = idx_getIndex('i',$wlen);
617        foreach($wids[$wlen] as $ixid){
618            if($ixid < count($index))
619                $docs["$wlen*$ixid"] = idx_parseIndexLine($page_idx,$index[$ixid]);
620        }
621    }
622
623    // merge found pages into final result array
624    $final = array();
625    foreach($result as $word => $res){
626        $final[$word] = array();
627        foreach($res as $wid){
628            $hits = &$docs[$wid];
629            foreach ($hits as $hitkey => $hitcnt) {
630                if (!isset($final[$word][$hitkey])) {
631                    $final[$word][$hitkey] = $hitcnt;
632                } else {
633                    $final[$word][$hitkey] += $hitcnt;
634                }
635            }
636        }
637    }
638    return $final;
639}
640
641/**
642 * Returns a list of documents and counts from a index line
643 *
644 * It omits docs with a count of 0 and pages that no longer
645 * exist.
646 *
647 * @param  array  $page_idx The list of known pages
648 * @param  string $line     A line from the main index
649 * @author Andreas Gohr <andi@splitbrain.org>
650 */
651function idx_parseIndexLine(&$page_idx,$line){
652    $result = array();
653
654    $line = trim($line);
655    if($line == '') return $result;
656
657    $parts = explode(':',$line);
658    foreach($parts as $part){
659        if($part == '') continue;
660        list($doc,$cnt) = explode('*',$part);
661        if(!$cnt) continue;
662        $doc = trim($page_idx[$doc]);
663        if(!$doc) continue;
664        // make sure the document still exists
665        if(!page_exists($doc,'',false)) continue;
666
667        $result[$doc] = $cnt;
668    }
669    return $result;
670}
671
672/**
673 * Tokenizes a string into an array of search words
674 *
675 * Uses the same algorithm as idx_getPageWords()
676 *
677 * @param string   $string     the query as given by the user
678 * @param arrayref $stopwords  array of stopwords
679 * @param boolean  $wc         are wildcards allowed?
680 */
681function idx_tokenizer($string,&$stopwords,$wc=false){
682    $words = array();
683    $wc = ($wc) ? '' : $wc = '\*';
684
685    if(preg_match('/[^0-9A-Za-z]/u', $string)){
686        // handle asian chars as single words (may fail on older PHP version)
687        $asia = @preg_replace('/('.IDX_ASIAN.')/u',' \1 ',$string);
688        if(!is_null($asia)) $string = $asia; //recover from regexp failure
689
690        $arr = explode(' ', utf8_stripspecials($string,' ','\._\-:'.$wc));
691        foreach ($arr as $w) {
692            if (!is_numeric($w) && strlen($w) < IDX_MINWORDLENGTH) continue;
693            $w = utf8_strtolower($w);
694            if($stopwords && is_int(array_search("$w\n",$stopwords))) continue;
695            $words[] = $w;
696        }
697    }else{
698        $w = $string;
699        if (!is_numeric($w) && strlen($w) < IDX_MINWORDLENGTH) return $words;
700        $w = strtolower($w);
701        if(is_int(array_search("$w\n",$stopwords))) return $words;
702        $words[] = $w;
703    }
704
705    return $words;
706}
707
708//Setup VIM: ex: et ts=4 :
709