Had stopped working with recent changes elsewhere, now fixed
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 26 Jun 2004 01:42:16 +0000 (01:42 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 26 Jun 2004 01:42:16 +0000 (01:42 +0000)
maintenance/rebuildtextindex.inc
maintenance/rebuildtextindex.php

index 65800ed..2608226 100644 (file)
@@ -6,40 +6,50 @@
 # Rebuilding is faster if you drop the index and recreate it,
 # but that will prevent searches from working while it runs.
 
-function dropTextIndex()
+define( "RTI_CHUNK_SIZE", 500 );
+
+function dropTextIndex( &$database )
 {
        if ( wfIndexExists( "searchindex", "si_title" ) ) {
                echo "Dropping index...\n";
                $sql = "ALTER TABLE searchindex DROP INDEX si_title, DROP INDEX si_text";
-               $res = wfQuery($sql, DB_WRITE, "dropTextIndex" );
+               $database->query($sql, "dropTextIndex" );
        }
+       # Truncate table, in an attempt to bring the slaves to a consistent state
+       # (zwinger was accidentally written to)
+       $database->query( "TRUNCATE TABLE searchindex", "dropTextIndex" );
 }
 
-function createTextIndex()
+function createTextIndex( &$database )
 {
        echo "Rebuild the index...\n";
        $sql = "ALTER TABLE searchindex ADD FULLTEXT si_title (si_title), " .
          "ADD FULLTEXT si_text (si_text)";
-       $res = wfQuery($sql, DB_WRITE, "createTextIndex" );
+       $database->query($sql, "createTextIndex" );
 }
 
-function rebuildTextIndex()
+function rebuildTextIndex( &$database )
 {
-       $sql = "SELECT COUNT(*) AS count FROM cur";
-       $res = wfQuery($sql, DB_READ, "rebuildTextIndex" );
+       $sql = "SELECT MAX(cur_id) AS count FROM cur";
+       $res = $database->query($sql, "rebuildTextIndex" );
        $s = wfFetchObject($res);
-       echo "Rebuilding index fields for {$s->count} pages...\n";
+       $count = $s->count;
+       echo "Rebuilding index fields for {$count} pages...\n";
        $n = 0;
 
-       $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur";
-       $res = wfQuery($sql, DB_READ, "rebuildTextIndex" );
-
-       while( $s = wfFetchObject($res) ) {
-               $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
-               $u->doUpdate();
-               if ( ( (++$n) % 500) == 0) { echo "$n\n"; }
+       while ( $n < $count ) {
+               print "$n\n";
+               $end = $n + RTI_CHUNK_SIZE - 1;
+               $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur WHERE cur_id BETWEEN $n AND $end";
+               $res = $database->query($sql, "rebuildTextIndex" );
+
+               while( $s = wfFetchObject($res) ) {
+                       $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
+                       $u->doUpdate();
+               }
+               wfFreeResult( $res );
+               $n += RTI_CHUNK_SIZE;
        }
-       wfFreeResult( $res );
 }
 
 ?>
index 83a4ea9..247fedc 100644 (file)
@@ -3,15 +3,14 @@
 # hours, depending on the database size and server configuration.
 
 require_once( "commandLine.inc" );
-require_once( "./rebuildtextindex.inc" );
+require_once( "rebuildtextindex.inc" );
 $wgTitle = Title::newFromText( "Rebuild text index script" );
 
-$wgDBuser                      = $wgDBadminuser;
-$wgDBpassword          = $wgDBadminpassword;
+$database = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
 
-dropTextIndex();
-rebuildTextIndex();
-createTextIndex();
+dropTextIndex( $database );
+rebuildTextIndex( $database );
+createTextIndex( $database );
 
 print "Done.\n";
 exit();