MediaWiki master
SearchIndexFieldDefinition.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Search;
4
15
21 protected $name;
22
28 protected $type;
29
35 protected $flags = 0;
36
41 protected $subfields = [];
42
46 private $mergeCallback;
47
52 public function __construct( $name, $type ) {
53 $this->name = $name;
54 $this->type = $type;
55 }
56
61 public function getName() {
62 return $this->name;
63 }
64
68 public function getIndexType() {
69 return $this->type;
70 }
71
80 public function setFlag( $flag, $unset = false ) {
81 if ( $unset ) {
82 $this->flags &= ~$flag;
83 } else {
84 $this->flags |= $flag;
85 }
86 return $this;
87 }
88
96 public function checkFlag( $flag ) {
97 return $this->flags & $flag;
98 }
99
107 public function merge( SearchIndexField $that ) {
108 if ( $this->mergeCallback ) {
109 return ( $this->mergeCallback )( $this, $that );
110 }
111 // TODO: which definitions may be compatible?
112 if ( ( $that instanceof self ) && $this->type === $that->type &&
113 $this->flags === $that->flags && $this->type !== self::INDEX_TYPE_NESTED
114 ) {
115 return $that;
116 }
117 return false;
118 }
119
123 public function getSubfields() {
124 return $this->subfields;
125 }
126
131 public function setSubfields( array $subfields ) {
132 $this->subfields = $subfields;
133 return $this;
134 }
135
141 abstract public function getMapping( SearchEngine $engine );
142
147 public function setMergeCallback( $callback ) {
148 $this->mergeCallback = $callback;
149 }
150
154 public function getEngineHints( SearchEngine $engine ) {
155 return [];
156 }
157}
158
160class_alias( SearchIndexFieldDefinition::class, 'SearchIndexFieldDefinition' );
Contain a class for special pages.
Basic infrastructure of the field definition.
merge(SearchIndexField $that)
Merge two field definitions if possible.
getEngineHints(SearchEngine $engine)
A list of search engine hints for this field.Hints are usually specific to a search engine implementa...
setMergeCallback( $callback)
Set field-specific merge strategy.
SearchIndexFieldDefinition[] $subfields
Subfields.
string $type
Type of the field, one of the constants above.
setFlag( $flag, $unset=false)
Set global flag for this field.
Definition of a mapping for the search index field.