| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
abstract class SearchIndexFieldDefinition implements SearchIndexField { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
protected $name; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
protected $type; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
protected $flags = 0; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
protected $subfields = []; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
private $mergeCallback; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function __construct( $name, $type ) { |
| 51 |
$this->name = $name; |
| 52 |
$this->type = $type; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public function getName() { |
| 60 |
return $this->name; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public function getIndexType() { |
| 67 |
return $this->type; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 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 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public function checkFlag( $flag ) { |
| 95 |
return $this->flags & $flag; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public function merge( SearchIndexField $that ) { |
| 106 |
if ( $this->mergeCallback ) { |
| 107 |
return call_user_func( $this->mergeCallback, $this, $that ); |
| 108 |
} |
| 109 |
|
| 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 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public function getSubfields() { |
| 122 |
return $this->subfields; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public function setSubfields( array $subfields ) { |
| 130 |
$this->subfields = $subfields; |
| 131 |
return $this; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
abstract public function getMapping( SearchEngine $engine ); |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public function setMergeCallback( $callback ) { |
| 146 |
$this->mergeCallback = $callback; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public function getEngineHints( SearchEngine $engine ) { |
| 153 |
return []; |
| 154 |
} |
| 155 |
} |