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\CirrusConfigNames;
6use CirrusSearch\CirrusSearch;
7use CirrusSearch\SearchConfig;
8use MediaWiki\MediaWikiServices;
9
10/**
11 * Builds search mapping configuration arrays for the suggester index.
12 *
13 * @license GPL-2.0-or-later
14 */
15class SuggesterMappingConfigBuilder {
16    /** @var SearchConfig */
17    private $config;
18
19    /**
20     * @param SearchConfig|null $config
21     */
22    public function __construct( ?SearchConfig $config = null ) {
23        $this->config = $config ?? MediaWikiServices::getInstance()->getConfigFactory()
24            ->makeConfig( CirrusSearch::NAME );
25    }
26
27    /**
28     * @return array
29     */
30    public function buildConfig() {
31        $suggest = [
32            'dynamic' => false,
33            '_source' => [ 'enabled' => true ],
34            'properties' => [
35                'batch_id' => [ 'type' => 'long' ],
36                'source_doc_id' => [ 'type' => 'keyword' ],
37                // Sadly we can't reuse the same input
38                // into multiple fields, it would help
39                // us to save space since we now have
40                // to store the source.
41                'suggest' => [
42                    'type' => 'completion',
43                    'analyzer' => 'plain',
44                    'search_analyzer' => 'plain_search',
45                    'max_input_length' => 255,
46                ],
47                'suggest-stop' => [
48                    'type' => 'completion',
49                    'analyzer' => 'stop_analyzer',
50                    'search_analyzer' => 'stop_analyzer_search',
51                    'preserve_separators' => false,
52                    'preserve_position_increments' => false,
53                    'max_input_length' => 255,
54                ],
55            ]
56        ];
57        if ( $this->config->getElement( CirrusConfigNames::CompletionSuggesterSubphrases, 'build' ) ) {
58            $suggest['properties']['suggest-subphrases'] = [
59                'type' => 'completion',
60                'analyzer' => 'subphrases',
61                'search_analyzer' => 'subphrases_search',
62                'max_input_length' => 255,
63            ];
64
65        }
66        return $suggest;
67    }
68
69}