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