Allow individual search backends to control whether they SearchUpdate
authorChad Horohoe <chadh@wikimedia.org>
Tue, 13 Aug 2013 22:54:03 +0000 (15:54 -0700)
committerDemon <chadh@wikimedia.org>
Wed, 14 Aug 2013 17:55:04 +0000 (17:55 +0000)
$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
includes/search/SearchEngine.php
includes/search/SearchUpdate.php

index 50b97a3..1f25b47 100644 (file)
@@ -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
index bfe7dda..b691c75 100644 (file)
@@ -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;
+       }
 }
 
 /**
index 7146917..22e4724 100644 (file)
@@ -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__ );
        }