* add uniwiki/CreatePage extension to core
[lhc/web/wiklou.git] / maintenance / rebuildtextindex.inc
index 04e0eb6..0f58fff 100644 (file)
@@ -1,11 +1,18 @@
 <?php
+require_once 'counter.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.
+ *
+ * @file
+ * @todo document
+ * @ingroup Maintenance
+ */
 
-# 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 )
@@ -21,7 +28,7 @@ function dropTextIndex( &$database )
 function createTextIndex( &$database )
 {
        $searchindex = $database->tableName( 'searchindex' );
-       echo "Rebuild the index...\n";
+       echo "\nRebuild the index...\n";
        $sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
          "ADD FULLTEXT si_text (si_text)";
        $database->query($sql, "createTextIndex" );
@@ -29,9 +36,9 @@ function createTextIndex( &$database )
 
 function rebuildTextIndex( &$database )
 {
-       extract( $database->tableNames( 'cur', 'searchindex' ) );
+       list ($page, $revision, $text, $searchindex) = $database->tableNamesN( 'page', 'revision', 'text', 'searchindex' );
 
-       $sql = "SELECT MAX(cur_id) AS count FROM $cur";
+       $sql = "SELECT MAX(page_id) AS count FROM $page";
        $res = $database->query($sql, "rebuildTextIndex" );
        $s = $database->fetchObject($res);
        $count = $s->count;
@@ -39,18 +46,21 @@ function rebuildTextIndex( &$database )
        $n = 0;
 
        while ( $n < $count ) {
-               print "$n\n";
+               print_c( $n - 1, $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";
+               $sql = "SELECT page_id, page_namespace, page_title, old_flags, old_text
+                         FROM $page, $revision, $text
+                        WHERE page_id BETWEEN $n AND $end
+                          AND page_latest=rev_id
+                          AND rev_text_id=old_id";
                $res = $database->query($sql, "rebuildTextIndex" );
 
                while( $s = $database->fetchObject($res) ) {
-                       $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
+                       $revtext = Revision::getRevisionText( $s );
+                       $u = new SearchUpdate( $s->page_id, $s->page_title, $revtext );
                        $u->doUpdate();
                }
                $database->freeResult( $res );
                $n += RTI_CHUNK_SIZE;
        }
 }
-
-?>