minor aesthetic change
[lhc/web/wiklou.git] / maintenance / updateSearchIndex.inc
1 <?php
2
3 function updateSearchIndex( $start, $end, $maxLockTime, $quiet ) {
4 global $wgQuiet;
5 global $wgDisableSearchUpdate;
6
7 $fname = "updateSearchIndex";
8
9 $wgQuiet = $quiet;
10 $wgDisableSearchUpdate = false;
11
12 output( "Updating searchindex between $start and $end\n" );
13
14 # Select entries from recentchanges which are on top and between the specified times
15 $start = wfStrencode( $start );
16 $end = wfStrencode( $end );
17
18 $sql = "SELECT rc_cur_id,rc_type,rc_moved_to_ns,rc_moved_to_title FROM recentchanges
19 WHERE rc_this_oldid=0 AND rc_timestamp BETWEEN '$start' AND '$end'";
20 $res = wfQuery( $sql, DB_READ, $fname );
21
22 # Lock searchindex
23 if ( $maxLockTime ) {
24 output( " --- Waiting for lock ---" );
25 lockSearchindex();
26 $lockTime = time();
27 output( "\n" );
28 }
29
30 # Loop through the results and do a search update
31 while ( $row = wfFetchObject( $res ) ) {
32 # Allow reads to be processed
33 if ( $maxLockTime && time() > $lockTime + $maxLockTime ) {
34 output( " --- Relocking ---" );
35 relockSearchindex();
36 $lockTime = time();
37 output( "\n" );
38 }
39 if ( $row->rc_type == RC_LOG ) {
40 continue;
41 } elseif ( $row->rc_type == RC_MOVE || $row->rc_type == RC_MOVE_OVER_REDIRECT ) {
42 # Rename searchindex entry
43 $titleObj = Title::makeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title );
44 $title = $titleObj->getPrefixedDBkey();
45 output( "$title..." );
46 $u = new SearchUpdate( $row->rc_cur_id, $title, false );
47 output( "\n" );
48 } else {
49 # Get cur row
50 $curRow = wfGetArray( 'cur', array( 'cur_namespace', 'cur_title', 'cur_text' ), array( 'cur_id' => $row->rc_cur_id ) );
51 if ( $curRow ) {
52 $titleObj = Title::makeTitle( $curRow->cur_namespace, $curRow->cur_title );
53 $title = $titleObj->getPrefixedDBkey();
54 output( $title );
55 # Update searchindex
56 $u = new SearchUpdate( $row->rc_cur_id, $curRow->cur_title, $curRow->cur_text );
57 $u->doUpdate();
58 output( "\n" );
59 }
60 }
61 }
62
63 # Unlock searchindex
64 if ( $maxLockTime ) {
65 unlockSearchindex();
66 }
67 output( "Done\n" );
68 }
69
70 function lockSearchindex() {
71 wfQuery( "LOCK TABLES searchindex LOW_PRIORITY WRITE, cur READ", DB_WRITE );
72 }
73
74 function unlockSearchindex() {
75 wfQuery( "UNLOCK TABLES", DB_WRITE );
76 }
77
78 # Unlock and lock again
79 # Since the lock is low-priority, queued reads will be able to complete
80 function relockSearchindex() {
81 unlockSearchindex();
82 lockSearchindex();
83 }
84
85 function output( $text ) {
86 global $wgQuiet;
87 if ( !$wgQuiet ) {
88 print $text;
89 }
90 }
91
92 ?>