/**
* Do some database updates after deletion
*
- * @param int $id page_id value of the page being deleted (B/C, currently unused)
+ * @param int $id page_id value of the page being deleted
* @param $content Content: optional page content to be used when determining the required updates.
* This may be needed because $this->getContent() may already return null when the page proper was deleted.
*/
// Reset this object and the Title object
$this->loadFromRow( false, self::READ_LATEST );
+
+ // Search engine
+ DeferredUpdates::addUpdate( new SearchUpdate( $id, $this->mTitle ) );
}
/**
array( $dbw->lowPriorityOption() ) );
}
+ /**
+ * Delete an indexed page
+ * Title should be pre-processed.
+ *
+ * @param Integer $id Page id that was deleted
+ * @param String $title Title of page that was deleted
+ */
+ function delete( $id, $title ) {
+ $dbw = wfGetDB( DB_MASTER );
+
+ $dbw->delete( 'searchindex', array( 'si_page' => $id ), __METHOD__ );
+ }
+
/**
* Converts some characters for MySQL's indexing to grok it correctly,
* and pads short words to overcome limitations.
private $mId = 0, $mNamespace, $mTitle, $mText;
private $mTitleWords;
- function __construct( $id, $title, $text = false ) {
+ public function __construct( $id, $title, $text = false ) {
if ( is_string( $title ) ) {
$nt = Title::newFromText( $title );
} else {
}
}
- function doUpdate() {
- global $wgContLang, $wgDisableSearchUpdate;
+ public function doUpdate() {
+ global $wgDisableSearchUpdate;
if ( $wgDisableSearchUpdate || !$this->mId ) {
return;
wfProfileIn( __METHOD__ );
$search = SearchEngine::create();
- $lc = SearchEngine::legalSearchChars() . '&#;';
+ $normalTitle = $search->normalizeText( Title::indexTitle( $this->mNamespace, $this->mTitle ) );
- if ( $this->mText === false ) {
- $search->updateTitle( $this->mId,
- $search->normalizeText( Title::indexTitle( $this->mNamespace, $this->mTitle ) ) );
+ if ( WikiPage::newFromId( $this->mId ) === null ) {
+ $search->delete( $this->mId, $normalTitle );
+ wfProfileOut( __METHOD__ );
+ return;
+ } elseif ( $this->mText === false ) {
+ $search->updateTitle( $this->mId, $normalTitle );
wfProfileOut( __METHOD__ );
return;
}
+ $text = self::updateText( $this->mText );
+
+ wfRunHooks( 'SearchUpdate', array( $this->mId, $this->mNamespace, $this->mTitle, &$text ) );
+
+ # Perform the actual update
+ $search->update( $this->mId, $normalTitle, $search->normalizeText( $text ) );
+
+ wfProfileOut( __METHOD__ );
+ }
+
+ public static function updateText( $text ) {
+ global $wgContLang;
+
# Language-specific strip/conversion
- $text = $wgContLang->normalizeForSearch( $this->mText );
+ $text = $wgContLang->normalizeForSearch( $text );
+ $lc = SearchEngine::legalSearchChars() . '&#;';
wfProfileIn( __METHOD__ . '-regexps' );
$text = preg_replace( "/<\\/?\\s*[A-Za-z][^>]*?>/",
# Strip wiki '' and '''
$text = preg_replace( "/''[']*/", " ", $text );
wfProfileOut( __METHOD__ . '-regexps' );
-
- wfRunHooks( 'SearchUpdate', array( $this->mId, $this->mNamespace, $this->mTitle, &$text ) );
-
- # Perform the actual update
- $search->update( $this->mId, $search->normalizeText( Title::indexTitle( $this->mNamespace, $this->mTitle ) ),
- $search->normalizeText( $text ) );
-
- wfProfileOut( __METHOD__ );
+ return $text;
}
}
/**
* @group Search
+ * @group Database
*/
class SearchUpdateTest extends MediaWikiTestCase {
$this->setMwGlobals( 'wgSearchType', 'MockSearch' );
}
- function update( $text, $title = 'Test', $id = 1 ) {
- $u = new SearchUpdate( $id, $title, $text );
- $u->doUpdate();
-
- return array( MockSearch::$title, MockSearch::$text );
- }
-
function updateText( $text ) {
- list( , $resultText ) = $this->update( $text );
- $resultText = trim( $resultText ); // abstract from some implementation details
- return $resultText;
+ return trim( SearchUpdate::updateText( $text ) );
}
function testUpdateText() {