MediaWiki  master
SearchIndexFieldDefinition.php
Go to the documentation of this file.
1 <?php
2 
12 abstract class SearchIndexFieldDefinition implements SearchIndexField {
13 
19  protected $name;
20 
26  protected $type;
27 
33  protected $flags = 0;
34 
39  protected $subfields = [];
40 
44  private $mergeCallback;
45 
50  public function __construct( $name, $type ) {
51  $this->name = $name;
52  $this->type = $type;
53  }
54 
59  public function getName() {
60  return $this->name;
61  }
62 
66  public function getIndexType() {
67  return $this->type;
68  }
69 
78  public function setFlag( $flag, $unset = false ) {
79  if ( $unset ) {
80  $this->flags &= ~$flag;
81  } else {
82  $this->flags |= $flag;
83  }
84  return $this;
85  }
86 
94  public function checkFlag( $flag ) {
95  return $this->flags & $flag;
96  }
97 
105  public function merge( SearchIndexField $that ) {
106  if ( !empty( $this->mergeCallback ) ) {
107  return call_user_func( $this->mergeCallback, $this, $that );
108  }
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
112  ) {
113  return $that;
114  }
115  return false;
116  }
117 
121  public function getSubfields() {
122  return $this->subfields;
123  }
124 
129  public function setSubfields( array $subfields ) {
130  $this->subfields = $subfields;
131  return $this;
132  }
133 
139  abstract public function getMapping( SearchEngine $engine );
140 
145  public function setMergeCallback( $callback ) {
146  $this->mergeCallback = $callback;
147  }
148 
152  public function getEngineHints( SearchEngine $engine ) {
153  return [];
154  }
155 }
SearchIndexFieldDefinition\merge
merge(SearchIndexField $that)
Merge two field definitions if possible.
Definition: SearchIndexFieldDefinition.php:105
SearchIndexFieldDefinition\checkFlag
checkFlag( $flag)
Check if flag is set.
Definition: SearchIndexFieldDefinition.php:94
SearchIndexFieldDefinition\getName
getName()
Get field name.
Definition: SearchIndexFieldDefinition.php:59
SearchIndexFieldDefinition\getEngineHints
getEngineHints(SearchEngine $engine)
A list of search engine hints for this field.Hints are usually specific to a search engine implementa...
Definition: SearchIndexFieldDefinition.php:152
SearchIndexFieldDefinition\getIndexType
getIndexType()
Definition: SearchIndexFieldDefinition.php:66
SearchIndexFieldDefinition\$flags
int $flags
Bit flags for the field.
Definition: SearchIndexFieldDefinition.php:33
SearchIndexFieldDefinition\$name
string $name
Name of the field.
Definition: SearchIndexFieldDefinition.php:19
SearchIndexFieldDefinition\setSubfields
setSubfields(array $subfields)
Definition: SearchIndexFieldDefinition.php:129
SearchIndexFieldDefinition\__construct
__construct( $name, $type)
Definition: SearchIndexFieldDefinition.php:50
SearchIndexFieldDefinition\getMapping
getMapping(SearchEngine $engine)
SearchIndexFieldDefinition\setMergeCallback
setMergeCallback( $callback)
Set field-specific merge strategy.
Definition: SearchIndexFieldDefinition.php:145
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:37
SearchIndexFieldDefinition\getSubfields
getSubfields()
Definition: SearchIndexFieldDefinition.php:121
SearchIndexFieldDefinition\$type
string $type
Type of the field, one of the constants above.
Definition: SearchIndexFieldDefinition.php:26
SearchIndexFieldDefinition
Basic infrastructure of the field definition.
Definition: SearchIndexFieldDefinition.php:12
SearchIndexFieldDefinition\$subfields
SearchIndexFieldDefinition[] $subfields
Subfields.
Definition: SearchIndexFieldDefinition.php:39
SearchIndexField
Definition of a mapping for the search index field.
Definition: SearchIndexField.php:7
SearchIndexFieldDefinition\setFlag
setFlag( $flag, $unset=false)
Set global flag for this field.
Definition: SearchIndexFieldDefinition.php:78
SearchIndexFieldDefinition\$mergeCallback
callable $mergeCallback
Definition: SearchIndexFieldDefinition.php:44