Correct name for Nauruan according to http://en.wikipedia.org/w/wiki.phtml?title...
[mediawiki.git] / maintenance / rebuildtextindex.inc
blob13f4608127a8f4225c6c6e1ad70cc9246b53dc62
1 <?php
2 /**
3  * Rebuild the fulltext search indexes. This may take a while
4  * depending on the database size and server configuration.
5  *
6  * Rebuilding is faster if you drop the index and recreate it,
7  * but that will prevent searches from working while it runs.
8  *
9  * @todo document
10  * @package MediaWiki
11  * @subpackage Maintenance
12  */
14 /** */
15 define( "RTI_CHUNK_SIZE", 500 );
17 function dropTextIndex( &$database )
19         $searchindex = $database->tableName( 'searchindex' );
20         if ( $database->indexExists( "searchindex", "si_title" ) ) {
21                 echo "Dropping index...\n";
22                 $sql = "ALTER TABLE $searchindex DROP INDEX si_title, DROP INDEX si_text";
23                 $database->query($sql, "dropTextIndex" );
24         }
27 function createTextIndex( &$database )
29         $searchindex = $database->tableName( 'searchindex' );
30         echo "Rebuild the index...\n";
31         $sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
32           "ADD FULLTEXT si_text (si_text)";
33         $database->query($sql, "createTextIndex" );
36 function rebuildTextIndex( &$database )
38         extract( $database->tableNames( 'cur', 'searchindex' ) );
40         $sql = "SELECT MAX(cur_id) AS count FROM $cur";
41         $res = $database->query($sql, "rebuildTextIndex" );
42         $s = $database->fetchObject($res);
43         $count = $s->count;
44         echo "Rebuilding index fields for {$count} pages...\n";
45         $n = 0;
47         while ( $n < $count ) {
48                 print "$n\n";
49                 $end = $n + RTI_CHUNK_SIZE - 1;
50                 $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM $cur WHERE cur_id BETWEEN $n AND $end";
51                 $res = $database->query($sql, "rebuildTextIndex" );
53                 while( $s = $database->fetchObject($res) ) {
54                         $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
55                         $u->doUpdate();
56                 }
57                 $database->freeResult( $res );
58                 $n += RTI_CHUNK_SIZE;
59         }