65800edf3113daf2b52e14d830af6c52dc042acc
[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 function dropTextIndex()
10 {
11 if ( wfIndexExists( "searchindex", "si_title" ) ) {
12 echo "Dropping index...\n";
13 $sql = "ALTER TABLE searchindex DROP INDEX si_title, DROP INDEX si_text";
14 $res = wfQuery($sql, DB_WRITE, "dropTextIndex" );
15 }
16 }
17
18 function createTextIndex()
19 {
20 echo "Rebuild the index...\n";
21 $sql = "ALTER TABLE searchindex ADD FULLTEXT si_title (si_title), " .
22 "ADD FULLTEXT si_text (si_text)";
23 $res = wfQuery($sql, DB_WRITE, "createTextIndex" );
24 }
25
26 function rebuildTextIndex()
27 {
28 $sql = "SELECT COUNT(*) AS count FROM cur";
29 $res = wfQuery($sql, DB_READ, "rebuildTextIndex" );
30 $s = wfFetchObject($res);
31 echo "Rebuilding index fields for {$s->count} pages...\n";
32 $n = 0;
33
34 $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur";
35 $res = wfQuery($sql, DB_READ, "rebuildTextIndex" );
36
37 while( $s = wfFetchObject($res) ) {
38 $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
39 $u->doUpdate();
40 if ( ( (++$n) % 500) == 0) { echo "$n\n"; }
41 }
42 wfFreeResult( $res );
43 }
44
45 ?>