2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-03 20:33:01 +00:00
|
|
|
/**
|
|
|
|
|
* Rebuild search index table from scratch. This takes several
|
|
|
|
|
* hours, depending on the database size and server configuration.
|
|
|
|
|
*
|
2008-07-21 16:58:06 +00:00
|
|
|
* This is only for MySQL (see bug 9905).
|
|
|
|
|
* Postgres is trigger-based and should never need rebuilding.
|
2007-05-14 20:24:10 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2009-08-02 19:35:17 +00:00
|
|
|
* @todo document
|
2006-01-07 13:09:30 +00:00
|
|
|
*/
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
require_once( "Maintenance.php" );
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
class RebuildTextIndex extends Maintenance {
|
|
|
|
|
|
|
|
|
|
const RTI_CHUNK_SIZE = 500;
|
2007-05-14 20:24:10 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->mDescription = "Rebuild search index table from scratch";
|
|
|
|
|
}
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
|
|
|
|
global $wgTitle;
|
|
|
|
|
|
|
|
|
|
// Only do this for MySQL
|
|
|
|
|
$database = wfGetDB( DB_MASTER );
|
|
|
|
|
if( !$database instanceof DatabaseMysql ) {
|
2009-08-02 21:55:10 +00:00
|
|
|
$this->error( "This script is only for MySQL.", true );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$wgTitle = Title::newFromText( "Rebuild text index script" );
|
|
|
|
|
|
|
|
|
|
$this->dropTextIndex( $database );
|
|
|
|
|
$this->doRebuildTextIndex( $database );
|
|
|
|
|
$this->createTextIndex( $database );
|
|
|
|
|
|
|
|
|
|
$this->output( "Done.\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function dropTextIndex( &$database ) {
|
|
|
|
|
$searchindex = $database->tableName( 'searchindex' );
|
|
|
|
|
if ( $database->indexExists( "searchindex", "si_title" ) ) {
|
|
|
|
|
$this->output( "Dropping index...\n" );
|
|
|
|
|
$sql = "ALTER TABLE $searchindex DROP INDEX si_title, DROP INDEX si_text";
|
|
|
|
|
$database->query($sql, "dropTextIndex" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-05-02 22:55:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
private function createTextIndex( &$database ) {
|
|
|
|
|
$searchindex = $database->tableName( 'searchindex' );
|
|
|
|
|
$this->output( "\nRebuild the index...\n" );
|
|
|
|
|
$sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
|
|
|
|
|
"ADD FULLTEXT si_text (si_text)";
|
|
|
|
|
$database->query($sql, "createTextIndex" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doRebuildTextIndex( &$database ) {
|
|
|
|
|
list ($page, $revision, $text, $searchindex) = $database->tableNamesN( 'page', 'revision', 'text', 'searchindex' );
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT MAX(page_id) AS count FROM $page";
|
|
|
|
|
$res = $database->query($sql, "rebuildTextIndex" );
|
|
|
|
|
$s = $database->fetchObject($res);
|
|
|
|
|
$count = $s->count;
|
|
|
|
|
$this->output( "Rebuilding index fields for {$count} pages...\n" );
|
|
|
|
|
$n = 0;
|
|
|
|
|
|
|
|
|
|
while ( $n < $count ) {
|
|
|
|
|
$this->output( $n . "\n" );
|
|
|
|
|
$end = $n + self::RTI_CHUNK_SIZE - 1;
|
|
|
|
|
$sql = "SELECT page_id, page_namespace, page_title, old_flags, old_text
|
|
|
|
|
FROM $page, $revision, $text
|
|
|
|
|
WHERE page_id BETWEEN $n AND $end
|
|
|
|
|
AND page_latest=rev_id
|
|
|
|
|
AND rev_text_id=old_id";
|
|
|
|
|
$res = $database->query($sql, "rebuildTextIndex" );
|
|
|
|
|
|
|
|
|
|
while( $s = $database->fetchObject($res) ) {
|
|
|
|
|
$revtext = Revision::getRevisionText( $s );
|
|
|
|
|
$u = new SearchUpdate( $s->page_id, $s->page_title, $revtext );
|
|
|
|
|
$u->doUpdate();
|
|
|
|
|
}
|
|
|
|
|
$database->freeResult( $res );
|
|
|
|
|
$n += self::RTI_CHUNK_SIZE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$maintClass = "RebuildTextIndex";
|
|
|
|
|
require_once( DO_MAINTENANCE );
|