MediaWiki  1.34.0
SearchIndexFieldDefinition.php
Go to the documentation of this file.
1 <?php
2 
11 abstract class SearchIndexFieldDefinition implements SearchIndexField {
12 
18  protected $name;
19 
25  protected $type;
26 
32  protected $flags = 0;
33 
38  protected $subfields = [];
39 
43  private $mergeCallback;
44 
49  public function __construct( $name, $type ) {
50  $this->name = $name;
51  $this->type = $type;
52  }
53 
58  public function getName() {
59  return $this->name;
60  }
61 
66  public function getIndexType() {
67  return $this->type;
68  }
69 
77  public function setFlag( $flag, $unset = false ) {
78  if ( $unset ) {
79  $this->flags &= ~$flag;
80  } else {
81  $this->flags |= $flag;
82  }
83  return $this;
84  }
85 
91  public function checkFlag( $flag ) {
92  return $this->flags & $flag;
93  }
94 
101  public function merge( SearchIndexField $that ) {
102  if ( !empty( $this->mergeCallback ) ) {
103  return call_user_func( $this->mergeCallback, $this, $that );
104  }
105  // TODO: which definitions may be compatible?
106  if ( ( $that instanceof self ) && $this->type === $that->type &&
107  $this->flags === $that->flags && $this->type !== self::INDEX_TYPE_NESTED
108  ) {
109  return $that;
110  }
111  return false;
112  }
113 
118  public function getSubfields() {
119  return $this->subfields;
120  }
121 
127  public function setSubfields( array $subfields ) {
128  $this->subfields = $subfields;
129  return $this;
130  }
131 
137  abstract public function getMapping( SearchEngine $engine );
138 
143  public function setMergeCallback( $callback ) {
144  $this->mergeCallback = $callback;
145  }
146 
150  public function getEngineHints( SearchEngine $engine ) {
151  return [];
152  }
153 }
SearchIndexFieldDefinition\merge
merge(SearchIndexField $that)
Merge two field definitions if possible.
Definition: SearchIndexFieldDefinition.php:101
SearchIndexFieldDefinition\checkFlag
checkFlag( $flag)
Check if flag is set.
Definition: SearchIndexFieldDefinition.php:91
SearchIndexFieldDefinition\getName
getName()
Get field name.
Definition: SearchIndexFieldDefinition.php:58
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:150
SearchIndexFieldDefinition\getIndexType
getIndexType()
Get index type.
Definition: SearchIndexFieldDefinition.php:66
SearchIndexFieldDefinition\$flags
int $flags
Bit flags for the field.
Definition: SearchIndexFieldDefinition.php:32
SearchIndexFieldDefinition\$name
string $name
Name of the field.
Definition: SearchIndexFieldDefinition.php:18
SearchIndexFieldDefinition\setSubfields
setSubfields(array $subfields)
Set subfields.
Definition: SearchIndexFieldDefinition.php:127
SearchIndexFieldDefinition\__construct
__construct( $name, $type)
Definition: SearchIndexFieldDefinition.php:49
SearchIndexFieldDefinition\getMapping
getMapping(SearchEngine $engine)
SearchIndexFieldDefinition\setMergeCallback
setMergeCallback( $callback)
Set field-specific merge strategy.
Definition: SearchIndexFieldDefinition.php:143
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:34
SearchIndexFieldDefinition\getSubfields
getSubfields()
Get subfields.
Definition: SearchIndexFieldDefinition.php:118
SearchIndexFieldDefinition\$type
string $type
Type of the field, one of the constants above.
Definition: SearchIndexFieldDefinition.php:25
SearchIndexFieldDefinition
Basic infrastructure of the field definition.
Definition: SearchIndexFieldDefinition.php:11
SearchIndexFieldDefinition\$subfields
SearchIndexFieldDefinition[] $subfields
Subfields.
Definition: SearchIndexFieldDefinition.php:38
SearchIndexField
Definition of a mapping for the search index field.
Definition: SearchIndexField.php:6
SearchIndexFieldDefinition\setFlag
setFlag( $flag, $unset=false)
Set global flag for this field.
Definition: SearchIndexFieldDefinition.php:77
SearchIndexFieldDefinition\$mergeCallback
callable $mergeCallback
Definition: SearchIndexFieldDefinition.php:43