INSERT IGNORE for dumpUpdate() as well
[lhc/web/wiklou.git] / maintenance / rebuildtextindex.inc
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 define( "RTI_CHUNK_SIZE", 500 );
10
11 function dropTextIndex( &$database )
12 {
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" );
21 }
22
23 function createTextIndex( &$database )
24 {
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" );
29 }
30
31 function rebuildTextIndex( &$database )
32 {
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;
39
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" );
45
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 }
53 }
54
55 ?>