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( $dbw->timestamp( $start ) );
24 $end = $dbw->strencode( $dbw->timestamp( $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 $dbw->unlockTables( 'updateSearchIndex.inc ' . __METHOD__ );
84 function lockSearchindex( &$db ) {
85 $write = array( 'searchindex' );
86 $read = array( 'page', 'revision', 'text', 'interwiki' );
87 $db->lockTables( $read, $write, 'updateSearchIndex.inc ' . __METHOD__ );
90 # Unlock and lock again
91 # Since the lock is low-priority, queued reads will be able to complete
92 function relockSearchindex( &$db ) {
93 $db->unlockTables( 'updateSearchIndex.inc ' . __METHOD__ );
94 lockSearchindex( $db );
97 function output( $text ) {