675 return $texts; |
675 return $texts; |
676 } |
676 } |
677 |
677 |
678 /** |
678 /** |
679 * Rebuilds the search index |
679 * Rebuilds the search index |
|
680 * @param bool If true, prints out status messages |
680 */ |
681 */ |
681 |
682 |
682 function rebuild_search_index() |
683 function rebuild_search_index($verbose = false) |
683 { |
684 { |
684 global $db, $session, $paths, $template, $plugins; // Common objects |
685 global $db, $session, $paths, $template, $plugins; // Common objects |
685 $search = new Searcher(); |
686 $search = new Searcher(); |
|
687 if ( $verbose ) |
|
688 { |
|
689 echo '<p>'; |
|
690 } |
686 $texts = Array(); |
691 $texts = Array(); |
687 $textq = $db->sql_unbuffered_query($this->fetch_page_search_resource()); |
692 $textq = $db->sql_unbuffered_query($this->fetch_page_search_resource()); |
688 if(!$textq) $db->_die(''); |
693 if(!$textq) $db->_die(''); |
689 while($row = $db->fetchrow()) |
694 while($row = $db->fetchrow()) |
690 { |
695 { |
|
696 if ( $verbose ) |
|
697 { |
|
698 ob_start(); |
|
699 echo "Indexing page " . $this->nslist[$row['namespace']] . sanitize_page_id($row['page_id']) . "<br />"; |
|
700 ob_flush(); |
|
701 while (@ob_end_flush()); |
|
702 flush(); |
|
703 } |
691 if ( isset($this->nslist[$row['namespace']]) ) |
704 if ( isset($this->nslist[$row['namespace']]) ) |
692 { |
705 { |
693 $idstring = $this->nslist[$row['namespace']] . sanitize_page_id($row['page_id']); |
706 $idstring = $this->nslist[$row['namespace']] . sanitize_page_id($row['page_id']); |
694 if ( isset($this->pages[$idstring]) ) |
707 if ( isset($this->pages[$idstring]) ) |
695 { |
708 { |
704 { |
717 { |
705 $page = array('name' => dirtify_page_id($row['page_id'])); |
718 $page = array('name' => dirtify_page_id($row['page_id'])); |
706 } |
719 } |
707 $texts[(string)$row['page_idstring']] = $row['page_text'] . ' ' . $page['name']; |
720 $texts[(string)$row['page_idstring']] = $row['page_text'] . ' ' . $page['name']; |
708 } |
721 } |
|
722 if ( $verbose ) |
|
723 { |
|
724 ob_start(); |
|
725 echo "Calculating word list..."; |
|
726 ob_flush(); |
|
727 while (@ob_end_flush()); |
|
728 flush(); |
|
729 } |
709 $search->buildIndex($texts); |
730 $search->buildIndex($texts); |
|
731 if ( $verbose ) |
|
732 { |
|
733 echo '</p>'; |
|
734 } |
710 // echo '<pre>'.print_r($search->index, true).'</pre>'; |
735 // echo '<pre>'.print_r($search->index, true).'</pre>'; |
711 // return; |
736 // return; |
712 $q = $db->sql_query('DELETE FROM '.table_prefix.'search_index'); |
737 $q = $db->sql_query('DELETE FROM '.table_prefix.'search_index'); |
713 if(!$q) return false; |
738 if(!$q) return false; |
714 $secs = Array(); |
739 $secs = Array(); |