Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SuggesterMappingConfigBuilder | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
buildConfig | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Maintenance; |
4 | |
5 | use CirrusSearch\SearchConfig; |
6 | use MediaWiki\MediaWikiServices; |
7 | |
8 | /** |
9 | * Builds elasticsearch mapping configuration arrays for the suggester index. |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
15 | * |
16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. |
20 | * |
21 | * You should have received a copy of the GNU General Public License along |
22 | * with this program; if not, write to the Free Software Foundation, Inc., |
23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 | * http://www.gnu.org/copyleft/gpl.html |
25 | */ |
26 | class SuggesterMappingConfigBuilder { |
27 | /** |
28 | * Version number for the core analysis. Increment the major |
29 | * version when the analysis changes in an incompatible way, |
30 | * and change the minor version when it changes but isn't |
31 | * incompatible |
32 | */ |
33 | public const VERSION = '3.0'; |
34 | |
35 | /** @var SearchConfig */ |
36 | private $config; |
37 | |
38 | /** |
39 | * @param SearchConfig|null $config |
40 | */ |
41 | public function __construct( SearchConfig $config = null ) { |
42 | $this->config = $config ?? MediaWikiServices::getInstance()->getConfigFactory() |
43 | ->makeConfig( 'CirrusSearch' ); |
44 | } |
45 | |
46 | /** |
47 | * @return array |
48 | */ |
49 | public function buildConfig() { |
50 | $suggest = [ |
51 | 'dynamic' => false, |
52 | '_source' => [ 'enabled' => true ], |
53 | 'properties' => [ |
54 | 'batch_id' => [ 'type' => 'long' ], |
55 | 'source_doc_id' => [ 'type' => 'keyword' ], |
56 | // Sadly we can't reuse the same input |
57 | // into multiple fields, it would help |
58 | // us to save space since we now have |
59 | // to store the source. |
60 | 'suggest' => [ |
61 | 'type' => 'completion', |
62 | 'analyzer' => 'plain', |
63 | 'search_analyzer' => 'plain_search', |
64 | 'max_input_length' => 255, |
65 | ], |
66 | 'suggest-stop' => [ |
67 | 'type' => 'completion', |
68 | 'analyzer' => 'stop_analyzer', |
69 | 'search_analyzer' => 'stop_analyzer_search', |
70 | 'preserve_separators' => false, |
71 | 'preserve_position_increments' => false, |
72 | 'max_input_length' => 255, |
73 | ], |
74 | ] |
75 | ]; |
76 | if ( $this->config->getElement( 'CirrusSearchCompletionSuggesterSubphrases', 'build' ) ) { |
77 | $suggest['properties']['suggest-subphrases'] = [ |
78 | 'type' => 'completion', |
79 | 'analyzer' => 'subphrases', |
80 | 'search_analyzer' => 'subphrases_search', |
81 | 'max_input_length' => 255, |
82 | ]; |
83 | |
84 | } |
85 | return $suggest; |
86 | } |
87 | |
88 | } |