4 * Basic infrastructure of the field definition.
6 * Specific engines should extend this class and at least,
7 * override the getMapping method, but can reuse other parts.
12 abstract class SearchIndexFieldDefinition
implements SearchIndexField
{
22 * Type of the field, one of the constants above
29 * Bit flags for the field.
37 * @var SearchIndexFieldDefinition[]
39 protected $subfields = [];
44 private $mergeCallback;
47 * @param string $name Field name
48 * @param string $type Index type
50 public function __construct( $name, $type ) {
59 public function getName() {
66 public function getIndexType() {
71 * Set global flag for this field.
74 * @param int $flag Bit flag to set/unset
75 * @param bool $unset True if flag should be unset, false by default
78 public function setFlag( $flag, $unset = false ) {
80 $this->flags
&= ~
$flag;
82 $this->flags |
= $flag;
88 * Check if flag is set.
92 * @return int 0 if unset, !=0 if set
94 public function checkFlag( $flag ) {
95 return $this->flags
& $flag;
99 * Merge two field definitions if possible.
100 * @stable to override
102 * @param SearchIndexField $that
103 * @return SearchIndexField|false New definition or false if not mergeable.
105 public function merge( SearchIndexField
$that ) {
106 if ( $this->mergeCallback
) {
107 return call_user_func( $this->mergeCallback
, $this, $that );
109 // TODO: which definitions may be compatible?
110 if ( ( $that instanceof self
) && $this->type
=== $that->type
&&
111 $this->flags
=== $that->flags
&& $this->type
!== self
::INDEX_TYPE_NESTED
119 * @return SearchIndexFieldDefinition[]
121 public function getSubfields() {
122 return $this->subfields
;
126 * @param SearchIndexFieldDefinition[] $subfields
129 public function setSubfields( array $subfields ) {
130 $this->subfields
= $subfields;
135 * @param SearchEngine $engine
139 abstract public function getMapping( SearchEngine
$engine );
142 * Set field-specific merge strategy.
143 * @param callable $callback
145 public function setMergeCallback( $callback ) {
146 $this->mergeCallback
= $callback;
152 public function getEngineHints( SearchEngine
$engine ) {