Merge "mediawiki.user: Return a promise from getRights/getGroups"
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index 4f4e31d..71c05d8 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:
@@ -453,22 +454,45 @@ class SearchEngine {
         * Load up the appropriate search engine class for the currently
         * active database backend, and return a configured instance.
         *
+        * @param String $type Type of search backend, if not the default
         * @return SearchEngine
         */
-       public static function create() {
+       public static function create( $type = null ) {
                global $wgSearchType;
                $dbr = null;
-               if ( $wgSearchType ) {
+
+               $alternatives = self::getSearchTypes();
+
+               if ( $type && in_array( $type, $alternatives ) ) {
+                       $class = $type;
+               } elseif ( $wgSearchType !== null ) {
                        $class = $wgSearchType;
                } else {
                        $dbr = wfGetDB( DB_SLAVE );
                        $class = $dbr->getSearchEngine();
                }
+
                $search = new $class( $dbr );
                $search->setLimitOffset( 0, 0 );
                return $search;
        }
 
+       /**
+        * Return the search engines we support. If only $wgSearchType
+        * is set, it'll be an array of just that one item.
+        *
+        * @return array
+        */
+       public static function getSearchTypes() {
+               global $wgSearchType, $wgSearchTypeAlternatives;
+               static $alternatives = null;
+               if ( $alternatives === null ) {
+                       $alternatives = $wgSearchTypeAlternatives ?: array();
+                       array_unshift( $alternatives, $wgSearchType );
+               }
+               return $alternatives;
+       }
+
        /**
         * Create or update the search index record for the given page.
         * Title and text should be pre-processed.
@@ -537,6 +561,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;
+       }
 }
 
 /**
@@ -842,11 +877,11 @@ class SearchResult {
         * @return String: highlighted text snippet, null (and not '') if not supported
         */
        function getTextSnippet( $terms ) {
-               global $wgUser, $wgAdvancedSearchHighlighting;
+               global $wgAdvancedSearchHighlighting;
                $this->initText();
 
                // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
-               list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs( $wgUser );
+               list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs();
                $h = new SearchHighlighter();
                if ( $wgAdvancedSearchHighlighting ) {
                        return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars );