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