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