Article validation code (tab fix)
[mediawiki.git] / maintenance / rebuildtextindex.inc
blob04e0eb6fca3ac4b7faf13af4b874fd08d52eb77c
1 <?php
3 # Rebuild the fulltext search indexes. This may take a while
4 # depending on the database size and server configuration.
6 # Rebuilding is faster if you drop the index and recreate it,
7 # but that will prevent searches from working while it runs.
9 define( "RTI_CHUNK_SIZE", 500 );
11 function dropTextIndex( &$database )
13         $searchindex = $database->tableName( 'searchindex' );
14         if ( $database->indexExists( "searchindex", "si_title" ) ) {
15                 echo "Dropping index...\n";
16                 $sql = "ALTER TABLE $searchindex DROP INDEX si_title, DROP INDEX si_text";
17                 $database->query($sql, "dropTextIndex" );
18         }
21 function createTextIndex( &$database )
23         $searchindex = $database->tableName( 'searchindex' );
24         echo "Rebuild the index...\n";
25         $sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
26           "ADD FULLTEXT si_text (si_text)";
27         $database->query($sql, "createTextIndex" );
30 function rebuildTextIndex( &$database )
32         extract( $database->tableNames( 'cur', 'searchindex' ) );
34         $sql = "SELECT MAX(cur_id) AS count FROM $cur";
35         $res = $database->query($sql, "rebuildTextIndex" );
36         $s = $database->fetchObject($res);
37         $count = $s->count;
38         echo "Rebuilding index fields for {$count} pages...\n";
39         $n = 0;
41         while ( $n < $count ) {
42                 print "$n\n";
43                 $end = $n + RTI_CHUNK_SIZE - 1;
44                 $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM $cur WHERE cur_id BETWEEN $n AND $end";
45                 $res = $database->query($sql, "rebuildTextIndex" );
47                 while( $s = $database->fetchObject($res) ) {
48                         $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
49                         $u->doUpdate();
50                 }
51                 $database->freeResult( $res );
52                 $n += RTI_CHUNK_SIZE;
53         }