3 * @addtogroup Maintenance
7 function updateSearchIndex( $start, $end, $maxLockTime, $quiet ) {
9 global $wgDisableSearchUpdate;
11 $fname = "updateSearchIndex";
14 $wgDisableSearchUpdate = false;
16 $dbw = wfGetDB( DB_MASTER );
17 $recentchanges = $dbw->tableName( 'recentchanges' );
19 output( "Updating searchindex between $start and $end\n" );
21 # Select entries from recentchanges which are on top and between the specified times
22 $start = $dbw->strencode( $start );
23 $end = $dbw->strencode( $end );
25 $page = $dbw->tableName( 'page' );
26 $sql = "SELECT rc_cur_id,rc_type,rc_moved_to_ns,rc_moved_to_title FROM $recentchanges
27 JOIN $page ON rc_cur_id=page_id AND rc_this_oldid=page_latest
28 WHERE rc_timestamp BETWEEN '$start' AND '$end'
30 $res = $dbw->query( $sql, $fname );
35 output( " --- Waiting for lock ---" );
36 lockSearchindex( $dbw );
41 # Loop through the results and do a search update
42 while ( $row = $dbw->fetchObject( $res ) ) {
43 # Allow reads to be processed
44 if ( $maxLockTime && time() > $lockTime + $maxLockTime ) {
45 output( " --- Relocking ---" );
46 relockSearchindex( $dbw );
50 if ( $row->rc_type == RC_LOG ) {
52 } elseif ( $row->rc_type == RC_MOVE || $row->rc_type == RC_MOVE_OVER_REDIRECT ) {
53 # Rename searchindex entry
54 $titleObj = Title::makeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title );
55 $title = $titleObj->getPrefixedDBkey();
56 output( "$title..." );
57 $u = new SearchUpdate( $row->rc_cur_id, $title, false );
60 // Get current revision
61 $rev = Revision::loadFromPageId( $dbw, $row->rc_cur_id );
63 $titleObj = $rev->getTitle();
64 $title = $titleObj->getPrefixedDBkey();
67 $u = new SearchUpdate( $row->rc_cur_id, $titleObj->getText(), $rev->getText() );
76 output( " --- Unlocking --" );
77 unlockSearchindex( $dbw );
83 function lockSearchindex( &$db ) {
84 $write = array( 'searchindex' );
85 $read = array( 'page', 'revision', 'text', 'interwiki' );
88 foreach( $write as $table ) {
89 $items[] = $db->tableName( $table ) . ' LOW_PRIORITY WRITE';
91 foreach( $read as $table ) {
92 $items[] = $db->tableName( $table ) . ' READ';
94 $sql = "LOCK TABLES " . implode( ',', $items );
95 $db->query( $sql, 'updateSearchIndex.inc ' . __METHOD__ );
98 function unlockSearchindex( &$db ) {
99 $db->query( "UNLOCK TABLES", 'updateSearchIndex.inc ' . __METHOD__ );
102 # Unlock and lock again
103 # Since the lock is low-priority, queued reads will be able to complete
104 function relockSearchindex( &$db ) {
105 unlockSearchindex( $db );
106 lockSearchindex( $db );
109 function output( $text ) {