Merge "Add support for PHP7 random_bytes in favor of mcrypt_create_iv"
[lhc/web/wiklou.git] / includes / search / SearchIndexFieldDefinition.php
index 3a86c82..04344fd 100644 (file)
@@ -2,8 +2,10 @@
 
 /**
  * Basic infrastructure of the field definition.
- * Specific engines will need to override it at least for getMapping,
- * but can reuse other parts.
+ *
+ * Specific engines should extend this class and at at least,
+ * override the getMapping method, but can reuse other parts.
+ *
  * @since 1.28
  */
 abstract class SearchIndexFieldDefinition implements SearchIndexField {
@@ -31,6 +33,11 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
         */
        protected $subfields = [];
 
+       /**
+        * @var callable
+        */
+       private $mergeCallback;
+
        /**
         * SearchIndexFieldDefinition constructor.
         * @param string $name Field name
@@ -89,9 +96,12 @@ 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
+                       $this->flags === $that->flags && $this->type !== self::INDEX_TYPE_NESTED
                ) {
                        return $that;
                }
@@ -115,4 +125,19 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
                $this->subfields = $subfields;
                return $this;
        }
+
+       /**
+        * @param SearchEngine $engine
+        *
+        * @return array
+        */
+       abstract public function getMapping( SearchEngine $engine );
+
+       /**
+        * Set field-specific merge strategy.
+        * @param callable $callback
+        */
+       public function setMergeCallback( $callback ) {
+               $this->mergeCallback = $callback;
+       }
 }