*/
protected $subfields = [];
+ /**
+ * @var callable
+ */
+ private $mergeCallback;
+
/**
* SearchIndexFieldDefinition constructor.
* @param string $name Field name
* @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;
}
*/
abstract public function getMapping( SearchEngine $engine );
+ /**
+ * Set field-specific merge strategy.
+ * @param callable $callback
+ */
+ public function setMergeCallback( $callback ) {
+ $this->mergeCallback = $callback;
+ }
}