Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| HighlightedField | |
100.00% |
8 / 8 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getFieldName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTarget | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPriority | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| merge | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| toArray | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Search\Fetch; |
| 4 | |
| 5 | use CirrusSearch\Search\ArrayCirrusSearchResult; |
| 6 | |
| 7 | abstract class HighlightedField { |
| 8 | /** Priority for properties that are doc dependent (e.g. doc size) */ |
| 9 | public const DEFAULT_TARGET_PRIORITY = 100; |
| 10 | |
| 11 | /** Priority for properties that are query dependent (highlight in content) */ |
| 12 | public const QUERY_DEPENDENT_TARGET_PRIORITY = 200; |
| 13 | |
| 14 | /** Priority for properties that are query dependent and triggered using search keywords (intitle:foo highlight) */ |
| 15 | public const EXPERT_SYNTAX_PRIORITY = 300; |
| 16 | |
| 17 | public const TARGET_TITLE_SNIPPET = ArrayCirrusSearchResult::TITLE_SNIPPET; |
| 18 | |
| 19 | public const TARGET_REDIRECT_SNIPPET = ArrayCirrusSearchResult::REDIRECT_SNIPPET; |
| 20 | |
| 21 | public const TARGET_CATEGORY_SNIPPET = ArrayCirrusSearchResult::CATEGORY_SNIPPET; |
| 22 | |
| 23 | public const TARGET_MAIN_SNIPPET = ArrayCirrusSearchResult::TEXT_SNIPPET; |
| 24 | |
| 25 | public const TARGET_SECTION_SNIPPET = ArrayCirrusSearchResult::SECTION_SNIPPET; |
| 26 | |
| 27 | /** |
| 28 | * Priority for properties are query dependent and triggered using costly search keywords |
| 29 | * (for intitle:/foo[0-9]/ intitle:bar we will prefer the highlight on the regex over the simple intitle:bar) |
| 30 | */ |
| 31 | public const COSTLY_EXPERT_SYNTAX_PRIORITY = 400; |
| 32 | |
| 33 | /** @var string */ |
| 34 | private $fieldName; |
| 35 | |
| 36 | /** @var string */ |
| 37 | private $type; |
| 38 | |
| 39 | /** @var string */ |
| 40 | private $target; |
| 41 | |
| 42 | /** @var int */ |
| 43 | private $priority; |
| 44 | |
| 45 | /** |
| 46 | * @param string $type |
| 47 | * @param string $fieldName |
| 48 | * @param string $target |
| 49 | * @param int $priority |
| 50 | */ |
| 51 | public function __construct( $type, $fieldName, $target, $priority = self::DEFAULT_TARGET_PRIORITY ) { |
| 52 | $this->type = $type; |
| 53 | $this->fieldName = $fieldName; |
| 54 | $this->target = $target; |
| 55 | $this->priority = $priority; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return string |
| 60 | */ |
| 61 | public function getFieldName() { |
| 62 | return $this->fieldName; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return string |
| 67 | */ |
| 68 | public function getTarget() { |
| 69 | return $this->target; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @return int |
| 74 | */ |
| 75 | public function getPriority() { |
| 76 | return $this->priority; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return string |
| 81 | */ |
| 82 | public function getType() { |
| 83 | return $this->type; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @param HighlightedField $field |
| 88 | * @return HighlightedField |
| 89 | */ |
| 90 | abstract public function merge( HighlightedField $field ): HighlightedField; |
| 91 | |
| 92 | /** |
| 93 | * @return array an entry in the fields section of the highlighting part of a search request body |
| 94 | */ |
| 95 | abstract public function toArray(); |
| 96 | } |