wiki.techinc.nl/includes/search/SearchIndexFieldDefinition.php
Thiemo Kreuz 1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00

155 lines
2.8 KiB
PHP

<?php
/**
* Basic infrastructure of the field definition.
*
* Specific engines should extend this class and at least,
* override the getMapping method, but can reuse other parts.
*
* @stable to extend
* @since 1.28
*/
abstract class SearchIndexFieldDefinition implements SearchIndexField {
/**
* Name of the field
*
* @var string
*/
protected $name;
/**
* Type of the field, one of the constants above
*
* @var string
*/
protected $type;
/**
* Bit flags for the field.
*
* @var int
*/
protected $flags = 0;
/**
* Subfields
* @var SearchIndexFieldDefinition[]
*/
protected $subfields = [];
/**
* @var callable
*/
private $mergeCallback;
/**
* @param string $name Field name
* @param string $type Index type
*/
public function __construct( $name, $type ) {
$this->name = $name;
$this->type = $type;
}
/**
* Get field name
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @return string
*/
public function getIndexType() {
return $this->type;
}
/**
* Set global flag for this field.
* @stable to override
*
* @param int $flag Bit flag to set/unset
* @param bool $unset True if flag should be unset, false by default
* @return $this
*/
public function setFlag( $flag, $unset = false ) {
if ( $unset ) {
$this->flags &= ~$flag;
} else {
$this->flags |= $flag;
}
return $this;
}
/**
* Check if flag is set.
* @stable to override
*
* @param int $flag
* @return int 0 if unset, !=0 if set
*/
public function checkFlag( $flag ) {
return $this->flags & $flag;
}
/**
* Merge two field definitions if possible.
* @stable to override
*
* @param SearchIndexField $that
* @return SearchIndexField|false New definition or false if not mergeable.
*/
public function merge( SearchIndexField $that ) {
if ( !empty( $this->mergeCallback ) ) {
return call_user_func( $this->mergeCallback, $this, $that );
}
// TODO: which definitions may be compatible?
if ( ( $that instanceof self ) && $this->type === $that->type &&
$this->flags === $that->flags && $this->type !== self::INDEX_TYPE_NESTED
) {
return $that;
}
return false;
}
/**
* @return SearchIndexFieldDefinition[]
*/
public function getSubfields() {
return $this->subfields;
}
/**
* @param SearchIndexFieldDefinition[] $subfields
* @return $this
*/
public function setSubfields( array $subfields ) {
$this->subfields = $subfields;
return $this;
}
/**
* @param SearchEngine $engine
*
* @return array
*/
abstract public function getMapping( SearchEngine $engine );
/**
* Set field-specific merge strategy.
* @param callable $callback
*/
public function setMergeCallback( $callback ) {
$this->mergeCallback = $callback;
}
/**
* @inheritDoc
*/
public function getEngineHints( SearchEngine $engine ) {
return [];
}
}