8 function updateSearchIndex( $start, $end, $maxLockTime, $quiet ) {
10 global $wgDisableSearchUpdate;
12 $fname = "updateSearchIndex";
15 $wgDisableSearchUpdate = false;
17 $dbw = wfGetDB( DB_MASTER );
18 $recentchanges = $dbw->tableName( 'recentchanges' );
20 output( "Updating searchindex between $start and $end\n" );
22 # Select entries from recentchanges which are on top and between the specified times
23 $start = $dbw->strencode( $start );
24 $end = $dbw->strencode( $end );
26 $page = $dbw->tableName( 'page' );
27 $sql = "SELECT rc_cur_id,rc_type,rc_moved_to_ns,rc_moved_to_title FROM $recentchanges
28 JOIN $page ON rc_cur_id=page_id AND rc_this_oldid=page_latest
29 WHERE rc_timestamp BETWEEN '$start' AND '$end'
31 $res = $dbw->query( $sql, $fname );
36 output( " --- Waiting for lock ---" );
37 lockSearchindex( $dbw );
42 # Loop through the results and do a search update
43 while ( $row = $dbw->fetchObject( $res ) ) {
44 # Allow reads to be processed
45 if ( $maxLockTime && time() > $lockTime + $maxLockTime ) {
46 output( " --- Relocking ---" );
47 relockSearchindex( $dbw );
51 if ( $row->rc_type == RC_LOG ) {
53 } elseif ( $row->rc_type == RC_MOVE || $row->rc_type == RC_MOVE_OVER_REDIRECT ) {
54 # Rename searchindex entry
55 $titleObj = Title::makeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title );
56 $title = $titleObj->getPrefixedDBkey();
57 output( "$title..." );
58 $u = new SearchUpdate( $row->rc_cur_id, $title, false );
61 // Get current revision
62 $rev = Revision::loadFromPageId( $dbw, $row->rc_cur_id );
64 $titleObj = $rev->getTitle();
65 $title = $titleObj->getPrefixedDBkey();
68 $u = new SearchUpdate( $row->rc_cur_id, $titleObj->getText(), $rev->getText() );
77 output( " --- Unlocking --" );
78 unlockSearchindex( $dbw );
84 function lockSearchindex( &$db ) {
85 $write = array( 'searchindex' );
86 $read = array( 'page', 'revision', 'text', 'interwiki' );
89 foreach( $write as $table ) {
90 $items[] = $db->tableName( $table ) . ' LOW_PRIORITY WRITE';
92 foreach( $read as $table ) {
93 $items[] = $db->tableName( $table ) . ' READ';
95 $sql = "LOCK TABLES " . implode( ',', $items );
96 $db->query( $sql, 'updateSearchIndex.inc ' . __METHOD__ );
99 function unlockSearchindex( &$db ) {
100 $db->query( "UNLOCK TABLES", 'updateSearchIndex.inc ' . __METHOD__ );
103 # Unlock and lock again
104 # Since the lock is low-priority, queued reads will be able to complete
105 function relockSearchindex( &$db ) {
106 unlockSearchindex( $db );
107 lockSearchindex( $db );
110 function output( $text ) {