]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/rebuildtextindex.inc
MediaWiki 1.14.0-scripts
[autoinstallsdev/mediawiki.git] / maintenance / rebuildtextindex.inc
1 <?php
2 require_once 'counter.php';
3 /**
4  * Rebuild the fulltext search indexes. This may take a while
5  * depending on the database size and server configuration.
6  *
7  * Rebuilding is faster if you drop the index and recreate it,
8  * but that will prevent searches from working while it runs.
9  *
10  * @file
11  * @todo document
12  * @ingroup Maintenance
13  */
14
15 /** */
16 define( "RTI_CHUNK_SIZE", 500 );
17
18 function dropTextIndex( &$database )
19 {
20         $searchindex = $database->tableName( 'searchindex' );
21         if ( $database->indexExists( "searchindex", "si_title" ) ) {
22                 echo "Dropping index...\n";
23                 $sql = "ALTER TABLE $searchindex DROP INDEX si_title, DROP INDEX si_text";
24                 $database->query($sql, "dropTextIndex" );
25         }
26 }
27
28 function createTextIndex( &$database )
29 {
30         $searchindex = $database->tableName( 'searchindex' );
31         echo "\nRebuild the index...\n";
32         $sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
33           "ADD FULLTEXT si_text (si_text)";
34         $database->query($sql, "createTextIndex" );
35 }
36
37 function rebuildTextIndex( &$database )
38 {
39         list ($page, $revision, $text, $searchindex) = $database->tableNamesN( 'page', 'revision', 'text', 'searchindex' );
40
41         $sql = "SELECT MAX(page_id) AS count FROM $page";
42         $res = $database->query($sql, "rebuildTextIndex" );
43         $s = $database->fetchObject($res);
44         $count = $s->count;
45         echo "Rebuilding index fields for {$count} pages...\n";
46         $n = 0;
47
48         while ( $n < $count ) {
49                 print_c( $n - 1, $n);
50                 $end = $n + RTI_CHUNK_SIZE - 1;
51                 $sql = "SELECT page_id, page_namespace, page_title, old_flags, old_text
52                           FROM $page, $revision, $text
53                          WHERE page_id BETWEEN $n AND $end
54                            AND page_latest=rev_id
55                            AND rev_text_id=old_id";
56                 $res = $database->query($sql, "rebuildTextIndex" );
57
58                 while( $s = $database->fetchObject($res) ) {
59                         $revtext = Revision::getRevisionText( $s );
60                         $u = new SearchUpdate( $s->page_id, $s->page_title, $revtext );
61                         $u->doUpdate();
62                 }
63                 $database->freeResult( $res );
64                 $n += RTI_CHUNK_SIZE;
65         }
66 }