2 require_once 'counter.php';
4 * Rebuild the fulltext search indexes. This may take a while
5 * depending on the database size and server configuration.
7 * Rebuilding is faster if you drop the index and recreate it,
8 * but that will prevent searches from working while it runs.
12 * @ingroup Maintenance
16 define( "RTI_CHUNK_SIZE", 500 );
18 function dropTextIndex( &$database )
20 $searchindex = $database->tableName( 'searchindex' );
21 if ( $database->indexExists( "searchindex", "si_title" ) ) {
22 echo "Dropping index...\n";
23 $sql = "ALTER TABLE $searchindex DROP INDEX si_title, DROP INDEX si_text";
24 $database->query($sql, "dropTextIndex" );
28 function createTextIndex( &$database )
30 $searchindex = $database->tableName( 'searchindex' );
31 echo "\nRebuild the index...\n";
32 $sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
33 "ADD FULLTEXT si_text (si_text)";
34 $database->query($sql, "createTextIndex" );
37 function rebuildTextIndex( &$database )
39 list ($page, $revision, $text, $searchindex) = $database->tableNamesN( 'page', 'revision', 'text', 'searchindex' );
41 $sql = "SELECT MAX(page_id) AS count FROM $page";
42 $res = $database->query($sql, "rebuildTextIndex" );
43 $s = $database->fetchObject($res);
45 echo "Rebuilding index fields for {$count} pages...\n";
48 while ( $n < $count ) {
50 $end = $n + RTI_CHUNK_SIZE - 1;
51 $sql = "SELECT page_id, page_namespace, page_title, old_flags, old_text
52 FROM $page, $revision, $text
53 WHERE page_id BETWEEN $n AND $end
54 AND page_latest=rev_id
55 AND rev_text_id=old_id";
56 $res = $database->query($sql, "rebuildTextIndex" );
58 while( $s = $database->fetchObject($res) ) {
59 $revtext = Revision::getRevisionText( $s );
60 $u = new SearchUpdate( $s->page_id, $s->page_title, $revtext );
63 $database->freeResult( $res );