LinksUpdate uses SELECT FOR UPDATE, thus starting a new transaction. So we have to...
[mediawiki.git] / maintenance / rebuildtextindex.inc
blob26082263a20a75936c7626f6b59e41403cfebf09
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         if ( wfIndexExists( "searchindex", "si_title" ) ) {
14                 echo "Dropping index...\n";
15                 $sql = "ALTER TABLE searchindex DROP INDEX si_title, DROP INDEX si_text";
16                 $database->query($sql, "dropTextIndex" );
17         }
18         # Truncate table, in an attempt to bring the slaves to a consistent state
19         # (zwinger was accidentally written to)
20         $database->query( "TRUNCATE TABLE searchindex", "dropTextIndex" );
23 function createTextIndex( &$database )
25         echo "Rebuild the index...\n";
26         $sql = "ALTER TABLE searchindex ADD FULLTEXT si_title (si_title), " .
27           "ADD FULLTEXT si_text (si_text)";
28         $database->query($sql, "createTextIndex" );
31 function rebuildTextIndex( &$database )
33         $sql = "SELECT MAX(cur_id) AS count FROM cur";
34         $res = $database->query($sql, "rebuildTextIndex" );
35         $s = wfFetchObject($res);
36         $count = $s->count;
37         echo "Rebuilding index fields for {$count} pages...\n";
38         $n = 0;
40         while ( $n < $count ) {
41                 print "$n\n";
42                 $end = $n + RTI_CHUNK_SIZE - 1;
43                 $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur WHERE cur_id BETWEEN $n AND $end";
44                 $res = $database->query($sql, "rebuildTextIndex" );
46                 while( $s = wfFetchObject($res) ) {
47                         $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
48                         $u->doUpdate();
49                 }
50                 wfFreeResult( $res );
51                 $n += RTI_CHUNK_SIZE;
52         }