1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
# Rebuild the fulltext search indexes. This may take a while
# depending on the database size and server configuration.
# Rebuilding is faster if you drop the index and recreate it,
# but that will prevent searches from working while it runs.
define( "RTI_CHUNK_SIZE", 500 );
function dropTextIndex( &$database )
{
if ( wfIndexExists( "searchindex", "si_title" ) ) {
echo "Dropping index...\n";
$sql = "ALTER TABLE searchindex DROP INDEX si_title, DROP INDEX si_text";
$database->query($sql, "dropTextIndex" );
}
# Truncate table, in an attempt to bring the slaves to a consistent state
# (zwinger was accidentally written to)
$database->query( "TRUNCATE TABLE searchindex", "dropTextIndex" );
}
function createTextIndex( &$database )
{
echo "Rebuild the index...\n";
$sql = "ALTER TABLE searchindex ADD FULLTEXT si_title (si_title), " .
"ADD FULLTEXT si_text (si_text)";
$database->query($sql, "createTextIndex" );
}
function rebuildTextIndex( &$database )
{
$sql = "SELECT MAX(cur_id) AS count FROM cur";
$res = $database->query($sql, "rebuildTextIndex" );
$s = wfFetchObject($res);
$count = $s->count;
echo "Rebuilding index fields for {$count} pages...\n";
$n = 0;
while ( $n < $count ) {
print "$n\n";
$end = $n + RTI_CHUNK_SIZE - 1;
$sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur WHERE cur_id BETWEEN $n AND $end";
$res = $database->query($sql, "rebuildTextIndex" );
while( $s = wfFetchObject($res) ) {
$u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
$u->doUpdate();
}
wfFreeResult( $res );
$n += RTI_CHUNK_SIZE;
}
}
?>
|