Merge "parserTests: Add parser test with filename containing single quotes"
[lhc/web/wiklou.git] / includes / search / SearchIndexFieldDefinition.php
index 910fd77..d0d2b89 100644 (file)
@@ -9,24 +9,28 @@
  * @since 1.28
  */
 abstract class SearchIndexFieldDefinition implements SearchIndexField {
+
        /**
         * Name of the field
         *
         * @var string
         */
        protected $name;
+
        /**
         * Type of the field, one of the constants above
         *
-        * @var int
+        * @var string
         */
        protected $type;
+
        /**
         * Bit flags for the field.
         *
         * @var int
         */
        protected $flags = 0;
+
        /**
         * Subfields
         * @var SearchIndexFieldDefinition[]
@@ -34,9 +38,13 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
        protected $subfields = [];
 
        /**
-        * SearchIndexFieldDefinition constructor.
+        * @var callable
+        */
+       private $mergeCallback;
+
+       /**
         * @param string $name Field name
-        * @param int    $type Index type
+        * @param string $type Index type
         */
        public function __construct( $name, $type ) {
                $this->name = $name;
@@ -62,7 +70,7 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
        /**
         * Set global flag for this field.
         *
-        * @param int  $flag Bit flag to set/unset
+        * @param int $flag Bit flag to set/unset
         * @param bool $unset True if flag should be unset, false by default
         * @return $this
         */
@@ -77,7 +85,7 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
 
        /**
         * Check if flag is set.
-        * @param $flag
+        * @param int $flag
         * @return int 0 if unset, !=0 if set
         */
        public function checkFlag( $flag ) {
@@ -91,6 +99,9 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
         * @return SearchIndexField|false New definition or false if not mergeable.
         */
        public function merge( SearchIndexField $that ) {
+               if ( !empty( $this->mergeCallback ) ) {
+                       return call_user_func( $this->mergeCallback, $this, $that );
+               }
                // TODO: which definitions may be compatible?
                if ( ( $that instanceof self ) && $this->type === $that->type &&
                        $this->flags === $that->flags && $this->type !== self::INDEX_TYPE_NESTED
@@ -125,4 +136,18 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
         */
        abstract public function getMapping( SearchEngine $engine );
 
+       /**
+        * Set field-specific merge strategy.
+        * @param callable $callback
+        */
+       public function setMergeCallback( $callback ) {
+               $this->mergeCallback = $callback;
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function getEngineHints( SearchEngine $engine ) {
+               return [];
+       }
 }