AuthManager: Commit transaction after auto-creating a user
[mediawiki.git] / includes / search / SearchIndexFieldDefinition.php
blob3a86c82d0db192708cd2a66ae3f7bc6021f0038c
1 <?php
3 /**
4 * Basic infrastructure of the field definition.
5 * Specific engines will need to override it at least for getMapping,
6 * but can reuse other parts.
7 * @since 1.28
8 */
9 abstract class SearchIndexFieldDefinition implements SearchIndexField {
10 /**
11 * Name of the field
13 * @var string
15 protected $name;
16 /**
17 * Type of the field, one of the constants above
19 * @var int
21 protected $type;
22 /**
23 * Bit flags for the field.
25 * @var int
27 protected $flags = 0;
28 /**
29 * Subfields
30 * @var SearchIndexFieldDefinition[]
32 protected $subfields = [];
34 /**
35 * SearchIndexFieldDefinition constructor.
36 * @param string $name Field name
37 * @param int $type Index type
39 public function __construct( $name, $type ) {
40 $this->name = $name;
41 $this->type = $type;
44 /**
45 * Get field name
46 * @return string
48 public function getName() {
49 return $this->name;
52 /**
53 * Get index type
54 * @return int
56 public function getIndexType() {
57 return $this->type;
60 /**
61 * Set global flag for this field.
63 * @param int $flag Bit flag to set/unset
64 * @param bool $unset True if flag should be unset, false by default
65 * @return $this
67 public function setFlag( $flag, $unset = false ) {
68 if ( $unset ) {
69 $this->flags &= ~$flag;
70 } else {
71 $this->flags |= $flag;
73 return $this;
76 /**
77 * Check if flag is set.
78 * @param $flag
79 * @return int 0 if unset, !=0 if set
81 public function checkFlag( $flag ) {
82 return $this->flags & $flag;
85 /**
86 * Merge two field definitions if possible.
88 * @param SearchIndexField $that
89 * @return SearchIndexField|false New definition or false if not mergeable.
91 public function merge( SearchIndexField $that ) {
92 // TODO: which definitions may be compatible?
93 if ( ( $that instanceof self ) && $this->type === $that->type &&
94 $this->flags === $that->flags && $this->type !== self::INDEX_TYPE_NESTED
95 ) {
96 return $that;
98 return false;
102 * Get subfields
103 * @return SearchIndexFieldDefinition[]
105 public function getSubfields() {
106 return $this->subfields;
110 * Set subfields
111 * @param SearchIndexFieldDefinition[] $subfields
112 * @return $this
114 public function setSubfields( array $subfields ) {
115 $this->subfields = $subfields;
116 return $this;