Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SuggesterMappingConfigBuilder
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 buildConfig
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace CirrusSearch\Maintenance;
4
5use CirrusSearch\SearchConfig;
6use MediaWiki\MediaWikiServices;
7
8/**
9 * Builds search mapping configuration arrays for the suggester index.
10 *
11 * @license GPL-2.0-or-later
12 */
13class SuggesterMappingConfigBuilder {
14    /**
15     * Version number for the core analysis. Increment the major
16     * version when the analysis changes in an incompatible way,
17     * and change the minor version when it changes but isn't
18     * incompatible
19     */
20    public const VERSION = '3.0';
21
22    /** @var SearchConfig */
23    private $config;
24
25    /**
26     * @param SearchConfig|null $config
27     */
28    public function __construct( ?SearchConfig $config = null ) {
29        $this->config = $config ?? MediaWikiServices::getInstance()->getConfigFactory()
30            ->makeConfig( 'CirrusSearch' );
31    }
32
33    /**
34     * @return array
35     */
36    public function buildConfig() {
37        $suggest = [
38            'dynamic' => false,
39            '_source' => [ 'enabled' => true ],
40            'properties' => [
41                'batch_id' => [ 'type' => 'long' ],
42                'source_doc_id' => [ 'type' => 'keyword' ],
43                // Sadly we can't reuse the same input
44                // into multiple fields, it would help
45                // us to save space since we now have
46                // to store the source.
47                'suggest' => [
48                    'type' => 'completion',
49                    'analyzer' => 'plain',
50                    'search_analyzer' => 'plain_search',
51                    'max_input_length' => 255,
52                ],
53                'suggest-stop' => [
54                    'type' => 'completion',
55                    'analyzer' => 'stop_analyzer',
56                    'search_analyzer' => 'stop_analyzer_search',
57                    'preserve_separators' => false,
58                    'preserve_position_increments' => false,
59                    'max_input_length' => 255,
60                ],
61            ]
62        ];
63        if ( $this->config->getElement( 'CirrusSearchCompletionSuggesterSubphrases', 'build' ) ) {
64            $suggest['properties']['suggest-subphrases'] = [
65                'type' => 'completion',
66                'analyzer' => 'subphrases',
67                'search_analyzer' => 'subphrases_search',
68                'max_input_length' => 255,
69            ];
70
71        }
72        return $suggest;
73    }
74
75}