Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| WeightedTags | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
3.00 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getMapping | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| getEngineHints | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Search; |
| 4 | |
| 5 | use SearchEngine; |
| 6 | use SearchIndexFieldDefinition; |
| 7 | |
| 8 | /** |
| 9 | * Field definitions for the weighted_tags search feature. |
| 10 | * @see WeightedTagsHooks |
| 11 | */ |
| 12 | class WeightedTags extends SearchIndexFieldDefinition { |
| 13 | /** |
| 14 | * @var string |
| 15 | */ |
| 16 | private $indexAnalyzer; |
| 17 | /** |
| 18 | * @var string |
| 19 | */ |
| 20 | private $searchAnalyzer; |
| 21 | /** |
| 22 | * @var string |
| 23 | */ |
| 24 | private $similarity; |
| 25 | |
| 26 | /** |
| 27 | * @param string $name name of the field |
| 28 | * @param string $type type of the field |
| 29 | * @param string $indexAnalyzer |
| 30 | * @param string $searchAnalyzer |
| 31 | * @param string $similarity similiraty name to use |
| 32 | */ |
| 33 | public function __construct( |
| 34 | $name, |
| 35 | $type, |
| 36 | string $indexAnalyzer, |
| 37 | string $searchAnalyzer, |
| 38 | string $similarity |
| 39 | ) { |
| 40 | parent::__construct( $name, $type ); |
| 41 | $this->indexAnalyzer = $indexAnalyzer; |
| 42 | $this->searchAnalyzer = $searchAnalyzer; |
| 43 | $this->similarity = $similarity; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @param SearchEngine $engine the search engine requesting this mapping |
| 48 | * @return array the elasticsearch mapping for this field |
| 49 | */ |
| 50 | public function getMapping( SearchEngine $engine ) { |
| 51 | return [ |
| 52 | 'type' => 'text', |
| 53 | 'analyzer' => $this->indexAnalyzer, |
| 54 | 'search_analyzer' => $this->searchAnalyzer, |
| 55 | 'index_options' => 'freqs', |
| 56 | 'norms' => false, |
| 57 | 'similarity' => $this->similarity, |
| 58 | ]; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @inheritDoc |
| 63 | */ |
| 64 | public function getEngineHints( SearchEngine $engine ) { |
| 65 | // see https://github.com/wikimedia/search-extra/blob/master/docs/super_detect_noop.md |
| 66 | return [ CirrusIndexField::NOOP_HINT => CirrusIndexField::MULTILIST_HANDLER ]; |
| 67 | } |
| 68 | } |