From 2f8d250abd43da8a09350441fb4a0a7ce27a6036 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 26 Jun 2004 01:42:16 +0000 Subject: [PATCH] Had stopped working with recent changes elsewhere, now fixed --- maintenance/rebuildtextindex.inc | 42 ++++++++++++++++++++------------ maintenance/rebuildtextindex.php | 11 ++++----- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/maintenance/rebuildtextindex.inc b/maintenance/rebuildtextindex.inc index 65800edf31..26082263a2 100644 --- a/maintenance/rebuildtextindex.inc +++ b/maintenance/rebuildtextindex.inc @@ -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 ); } ?> diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index 83a4ea94e5..247fedc523 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -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(); -- 2.20.1