Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
77.78% |
7 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LabelsProviderFieldDefinitions | |
77.78% |
7 / 9 |
|
50.00% |
1 / 2 |
3.10 | |
0.00% |
0 / 1 |
| __construct | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
2.26 | |||
| getFields | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Wikibase\Search\Elastic\Fields; |
| 4 | |
| 5 | use MediaWiki\Config\ConfigFactory; |
| 6 | use Wikibase\Repo\Search\Fields\FieldDefinitions; |
| 7 | |
| 8 | /** |
| 9 | * Definitions for any entity that has labels. |
| 10 | * |
| 11 | * @license GPL-2.0-or-later |
| 12 | * @author Stas Malyshev |
| 13 | */ |
| 14 | class LabelsProviderFieldDefinitions implements FieldDefinitions { |
| 15 | |
| 16 | /** |
| 17 | * @var string[] |
| 18 | */ |
| 19 | private $languageCodes; |
| 20 | |
| 21 | /** |
| 22 | * @var array |
| 23 | */ |
| 24 | private $stemmingSettings; |
| 25 | |
| 26 | /** |
| 27 | * @param string[] $languageCodes |
| 28 | * @param ConfigFactory|null $configFactory |
| 29 | */ |
| 30 | public function __construct( array $languageCodes, ?ConfigFactory $configFactory = null ) { |
| 31 | $this->languageCodes = $languageCodes; |
| 32 | if ( $configFactory === null ) { |
| 33 | $this->stemmingSettings = []; |
| 34 | } else { |
| 35 | $this->stemmingSettings = $configFactory->makeConfig( 'WikibaseCirrusSearch' ) |
| 36 | ->get( 'UseStemming' ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @return WikibaseLabelsIndexField[] |
| 42 | */ |
| 43 | public function getFields() { |
| 44 | return [ |
| 45 | LabelsField::NAME => new LabelsField( $this->languageCodes, $this->stemmingSettings ), |
| 46 | AllLabelsField::NAME => new AllLabelsField(), |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | } |