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
{
19 * Type of the field, one of the constants above
25 * Bit flags for the field.
32 * @var SearchIndexFieldDefinition[]
34 protected $subfields = [];
37 * SearchIndexFieldDefinition constructor.
38 * @param string $name Field name
39 * @param int $type Index type
41 public function __construct( $name, $type ) {
50 public function getName() {
58 public function getIndexType() {
63 * Set global flag for this field.
65 * @param int $flag Bit flag to set/unset
66 * @param bool $unset True if flag should be unset, false by default
69 public function setFlag( $flag, $unset = false ) {
71 $this->flags
&= ~
$flag;
73 $this->flags |
= $flag;
79 * Check if flag is set.
81 * @return int 0 if unset, !=0 if set
83 public function checkFlag( $flag ) {
84 return $this->flags
& $flag;
88 * Merge two field definitions if possible.
90 * @param SearchIndexField $that
91 * @return SearchIndexField|false New definition or false if not mergeable.
93 public function merge( SearchIndexField
$that ) {
94 // TODO: which definitions may be compatible?
95 if ( ( $that instanceof self
) && $this->type
=== $that->type
&&
96 $this->flags
=== $that->flags
&& $this->type
!== self
::INDEX_TYPE_NESTED
105 * @return SearchIndexFieldDefinition[]
107 public function getSubfields() {
108 return $this->subfields
;
113 * @param SearchIndexFieldDefinition[] $subfields
116 public function setSubfields( array $subfields ) {
117 $this->subfields
= $subfields;
122 * @param SearchEngine $engine
126 abstract public function getMapping( SearchEngine
$engine );