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