Merge "MovePage: Fix old, old bug with moving over redirects"
[lhc/web/wiklou.git] / includes / search / SearchEngine.php
index 27b6dd4..c2ccca0 100644 (file)
@@ -54,6 +54,12 @@ abstract class SearchEngine {
        /** @var array Feature values */
        protected $features = [];
 
+       /** @const string profile type for completionSearch */
+       const COMPLETION_PROFILE_TYPE = 'completionSearchProfile';
+
+       /** @const string profile type for query independent ranking features */
+       const FT_QUERY_INDEP_PROFILE_TYPE = 'fulltextQueryIndepProfile';
+
        /**
         * Perform a full text search query and return a result set.
         * If full text searches are not supported or disabled, return null.
@@ -607,7 +613,7 @@ abstract class SearchEngine {
         * @return array
         */
        public static function namespacesAsText( $namespaces ) {
-               return MediaWikiServices::getInstance()->getSearchEngineConfig()->namespacesAsText();
+               return MediaWikiServices::getInstance()->getSearchEngineConfig()->namespacesAsText( $namespaces );
        }
 
        /**
@@ -631,6 +637,64 @@ abstract class SearchEngine {
                return MediaWikiServices::getInstance()->getSearchEngineConfig()->getSearchTypes();
        }
 
+       /**
+        * Get a list of supported profiles.
+        * Some search engine implementations may expose specific profiles to fine-tune
+        * its behaviors.
+        * The profile can be passed as a feature data with setFeatureData( $profileType, $profileName )
+        * The array returned by this function contains the following keys:
+        * - name: the profile name to use with setFeatureData
+        * - desc-message: the i18n description
+        * - default: set to true if this profile is the default
+        *
+        * @since 1.28
+        * @param $profileType the type of profiles
+        * @return array|null the list of profiles or null if none available
+        */
+       public function getProfiles( $profileType ) {
+               return null;
+       }
+
+       /**
+        * Create a search field definition.
+        * Specific search engines should override this method to create search fields.
+        * @param string $name
+        * @param int    $type One of the types in SearchIndexField::INDEX_TYPE_*
+        * @return SearchIndexField
+        * @since 1.28
+        */
+       public function makeSearchFieldMapping( $name, $type ) {
+               return new NullIndexField();
+       }
+
+       /**
+        * Get fields for search index
+        * @since 1.28
+        * @return SearchIndexField[] Index field definitions for all content handlers
+        */
+       public function getSearchIndexFields() {
+               $models = ContentHandler::getContentModels();
+               $fields = [];
+               foreach ( $models as $model ) {
+                       $handler = ContentHandler::getForModelID( $model );
+                       $handlerFields = $handler->getFieldsForSearchIndex( $this );
+                       foreach ( $handlerFields as $fieldName => $fieldData ) {
+                               if ( empty( $fields[$fieldName] ) ) {
+                                       $fields[$fieldName] = $fieldData;
+                               } else {
+                                       // TODO: do we allow some clashes with the same type or reject all of them?
+                                       $mergeDef = $fields[$fieldName]->merge( $fieldData );
+                                       if ( !$mergeDef ) {
+                                               throw new InvalidArgumentException( "Duplicate field $fieldName for model $model" );
+                                       }
+                                       $fields[$fieldName] = $mergeDef;
+                               }
+                       }
+               }
+               // Hook to allow extensions to produce search mapping fields
+               Hooks::run( 'SearchIndexFields', [ &$fields, $this ] );
+               return $fields;
+       }
 }
 
 /**