New file form Christian List.
[mediawiki.git] / maintenance / rebuildtextindex.inc
blob8d681c8fdf20998b967780209af23b34319e4633
1 <?
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 function dropTextIndex()
11         echo "Dropping index...\n";
12         $sql = "ALTER TABLE searchindex DROP INDEX si_title, DROP INDEX si_text";
13         $res = wfQuery($sql);
16 function createTextIndex()
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);
24 function rebuildTextIndex()
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;
32         $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur";
33         $res = wfQuery($sql);
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 );