From 2bda9a37fe4a17c9c2c800d8fe052c583e4d7e2d Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 13 Aug 2013 15:54:03 -0700 Subject: [PATCH] Allow individual search backends to control whether they SearchUpdate $wgDisableSearchUpdate is a sledgehammer for disabling all indexing which is fine for most people, but sometimes you've got multiple search backends and you want some to update but not others. This allows each backend to tell core whether they support the feature. This also removes the SearchUpdate hook which really doesn't make sense and nobody uses but CirrusSearch and an abandoned extension from 7 years ago. Will require parallel change to MWSearch (Ibd002347) and Cirrus (I87a5b8cc) Change-Id: I2063fe05000044225fa6bec2171ed0071b84a5cf --- docs/hooks.txt | 7 ------ includes/search/SearchEngine.php | 12 +++++++++ includes/search/SearchUpdate.php | 42 ++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 50b97a3dc7..1f25b47ec5 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1976,13 +1976,6 @@ $data: the data stored in old_text. The meaning depends on $flags: if external $flags: a comma-delimited list of strings representing the options used. May include: utf8 (this will always be set for new revisions); gzip; external. -'SearchUpdate': Prior to search update completion. Return false to stop any -further text/content processing -$id : Page id -$title : Title object -$text : Current text being indexed -$content : Content object for text being indexed. - 'SearchGetNearMatchBefore': Perform exact-title-matches in "go" searches before the normal operations. $allSearchTerms : Array of the search terms in all content languages diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index bfe7dda4ce..b691c7545e 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -95,6 +95,7 @@ class SearchEngine { public function supports( $feature ) { switch ( $feature ) { case 'list-redirects': + case 'search-update': return true; case 'title-suffix-filter': default: @@ -557,6 +558,17 @@ class SearchEngine { public function getTextFromContent( Title $t, Content $c = null ) { return $c ? $c->getTextForSearchIndex() : ''; } + + /** + * If an implementation of SearchEngine handles all of its own text processing + * in getTextFromContent() and doesn't require SearchUpdate::updateText()'s + * rather silly handling, it should return true here instead. + * + * @return bool + */ + public function textAlreadyUpdatedForIndex() { + return false; + } } /** diff --git a/includes/search/SearchUpdate.php b/includes/search/SearchUpdate.php index 714691706a..22e4724fe1 100644 --- a/includes/search/SearchUpdate.php +++ b/includes/search/SearchUpdate.php @@ -89,27 +89,33 @@ class SearchUpdate implements DeferrableUpdate { wfProfileIn( __METHOD__ ); - $search = SearchEngine::create(); - $normalTitle = $search->normalizeText( - Title::indexTitle( $this->title->getNamespace(), $this->title->getText() ) ); + $page = WikiPage::newFromId( $this->id ); + $indexTitle = Title::indexTitle( $this->title->getNamespace(), $this->title->getText() ); - if ( WikiPage::newFromId( $this->id ) === null ) { - $search->delete( $this->id, $normalTitle ); - wfProfileOut( __METHOD__ ); - return; - } elseif ( $this->content === false ) { - $search->updateTitle( $this->id, $normalTitle ); - wfProfileOut( __METHOD__ ); - return; - } + foreach ( SearchEngine::getSearchTypes() as $type ) { + $search = SearchEngine::create( $type ); + if ( !$search->supports( 'search-update' ) ) { + continue; + } - $text = $search->getTextFromContent( $this->title, $this->content ); - if( wfRunHooks( 'SearchUpdate', array( $this->id, $this->title, &$text, $this->content ) ) ) { - $text = self::updateText( $text ); - } + $normalTitle = $search->normalizeText( $indexTitle ); - # Perform the actual update - $search->update( $this->id, $normalTitle, $search->normalizeText( $text ) ); + if ( $page === null ) { + $search->delete( $this->id, $normalTitle ); + continue; + } elseif ( $this->content === false ) { + $search->updateTitle( $this->id, $normalTitle ); + continue; + } + + $text = $search->getTextFromContent( $this->title, $this->content ); + if ( !$search->textAlreadyUpdatedForIndex() ) { + $text = self::updateText( $text ); + } + + # Perform the actual update + $search->update( $this->id, $normalTitle, $search->normalizeText( $text ) ); + } wfProfileOut( __METHOD__ ); } -- 2.20.1