4 * Basic infrastructure of the field definition.
6 * Specific engines should extend this class and at at least,
7 * override the getMapping method, but can reuse other parts.
11 abstract class SearchIndexFieldDefinition
implements SearchIndexField
{
21 * Type of the field, one of the constants above
28 * Bit flags for the field.
36 * @var SearchIndexFieldDefinition[]
38 protected $subfields = [];
43 private $mergeCallback;
46 * @param string $name Field name
47 * @param string $type Index type
49 public function __construct( $name, $type ) {
58 public function getName() {
66 public function getIndexType() {
71 * Set global flag for this field.
73 * @param int $flag Bit flag to set/unset
74 * @param bool $unset True if flag should be unset, false by default
77 public function setFlag( $flag, $unset = false ) {
79 $this->flags
&= ~
$flag;
81 $this->flags |
= $flag;
87 * Check if flag is set.
89 * @return int 0 if unset, !=0 if set
91 public function checkFlag( $flag ) {
92 return $this->flags
& $flag;
96 * Merge two field definitions if possible.
98 * @param SearchIndexField $that
99 * @return SearchIndexField|false New definition or false if not mergeable.
101 public function merge( SearchIndexField
$that ) {
102 if ( !empty( $this->mergeCallback
) ) {
103 return call_user_func( $this->mergeCallback
, $this, $that );
105 // TODO: which definitions may be compatible?
106 if ( ( $that instanceof self
) && $this->type
=== $that->type
&&
107 $this->flags
=== $that->flags
&& $this->type
!== self
::INDEX_TYPE_NESTED
116 * @return SearchIndexFieldDefinition[]
118 public function getSubfields() {
119 return $this->subfields
;
124 * @param SearchIndexFieldDefinition[] $subfields
127 public function setSubfields( array $subfields ) {
128 $this->subfields
= $subfields;
133 * @param SearchEngine $engine
137 abstract public function getMapping( SearchEngine
$engine );
140 * Set field-specific merge strategy.
141 * @param callable $callback
143 public function setMergeCallback( $callback ) {
144 $this->mergeCallback
= $callback;
150 public function getEngineHints( SearchEngine
$engine ) {