Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SourceTextIndexField | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getMapping | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Search; |
4 | |
5 | use CirrusSearch\CirrusSearch; |
6 | use CirrusSearch\SearchConfig; |
7 | use SearchEngine; |
8 | |
9 | /** |
10 | * Index field representing the source_text data. |
11 | * @package CirrusSearch |
12 | */ |
13 | class SourceTextIndexField extends TextIndexField { |
14 | /** @var bool enable trigram index for accelerated regex query */ |
15 | private $withTrigrams; |
16 | |
17 | /** |
18 | * @param string $name |
19 | * @param string $type |
20 | * @param SearchConfig $config |
21 | */ |
22 | public function __construct( $name, $type, SearchConfig $config ) { |
23 | parent::__construct( $name, $type, $config ); |
24 | |
25 | if ( $config->getElement( 'CirrusSearchWikimediaExtraPlugin', 'regex' ) && |
26 | in_array( 'build', $config->getElement( 'CirrusSearchWikimediaExtraPlugin', 'regex' ) ) |
27 | ) { |
28 | $this->withTrigrams = true; |
29 | } |
30 | } |
31 | |
32 | /** |
33 | * @param SearchEngine $engine |
34 | * @return array|void |
35 | */ |
36 | public function getMapping( SearchEngine $engine ) { |
37 | if ( !( $engine instanceof CirrusSearch ) ) { |
38 | throw new \LogicException( "Cannot map CirrusSearch fields for another engine." ); |
39 | } |
40 | $this->initFlags(); |
41 | |
42 | $field = [ |
43 | 'index' => false, // We only use the .plain field |
44 | 'type' => 'text', |
45 | 'fields' => [ |
46 | 'plain' => [ |
47 | 'type' => 'text', |
48 | 'norms' => false, |
49 | 'analyzer' => 'source_text_plain', |
50 | 'search_analyzer' => 'source_text_plain_search', |
51 | 'position_increment_gap' => self::POSITION_INCREMENT_GAP, |
52 | 'similarity' => self::getSimilarity( $this->config, $this->name, 'plain' ), |
53 | ], |
54 | ] |
55 | ]; |
56 | |
57 | if ( $this->withTrigrams ) { |
58 | $field['fields']['trigram'] = [ |
59 | 'norms' => false, |
60 | 'type' => 'text', |
61 | 'analyzer' => 'trigram', |
62 | 'index_options' => 'docs', |
63 | ]; |
64 | } |
65 | $this->configureHighlighting( $field, [ 'plain' ], false ); |
66 | return $field; |
67 | } |
68 | } |