Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
StatementProviderFieldDefinitions | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getFields | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
6 | |||
newFromSettings | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\Search\Elastic\Fields; |
4 | |
5 | use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; |
6 | use Wikibase\Lib\SettingsArray; |
7 | use Wikibase\Repo\Search\Fields\FieldDefinitions; |
8 | use Wikibase\Repo\Search\Fields\WikibaseIndexField; |
9 | |
10 | /** |
11 | * Fields for an object that has statements. |
12 | * |
13 | * @license GPL-2.0-or-later |
14 | * @author Stas Malyshev |
15 | */ |
16 | class StatementProviderFieldDefinitions implements FieldDefinitions { |
17 | |
18 | /** |
19 | * List of properties to index. |
20 | * @var string[] |
21 | */ |
22 | private $propertyIds; |
23 | |
24 | /** |
25 | * @var callable[] |
26 | */ |
27 | private $searchIndexDataFormatters; |
28 | /** |
29 | * @var PropertyDataTypeLookup |
30 | */ |
31 | private $propertyDataTypeLookup; |
32 | /** |
33 | * @var array |
34 | */ |
35 | private $indexedTypes; |
36 | /** |
37 | * @var array |
38 | */ |
39 | private $excludedIds; |
40 | /** |
41 | * @var array |
42 | */ |
43 | private $allowedQualifierPropertyIdsForQuantityStatements; |
44 | |
45 | public function __construct( |
46 | PropertyDataTypeLookup $propertyDataTypeLookup, |
47 | array $searchIndexDataFormatters, |
48 | array $propertyIds, |
49 | array $indexedTypes, |
50 | array $excludedIds, |
51 | array $allowedQualifierPropertyIdsForQuantityStatements |
52 | ) { |
53 | $this->propertyIds = $propertyIds; |
54 | $this->searchIndexDataFormatters = $searchIndexDataFormatters; |
55 | $this->propertyDataTypeLookup = $propertyDataTypeLookup; |
56 | $this->indexedTypes = $indexedTypes; |
57 | $this->excludedIds = $excludedIds; |
58 | $this->allowedQualifierPropertyIdsForQuantityStatements = |
59 | $allowedQualifierPropertyIdsForQuantityStatements; |
60 | } |
61 | |
62 | /** |
63 | * Get the list of definitions |
64 | * @return WikibaseIndexField[] key is field name, value is WikibaseIndexField |
65 | */ |
66 | public function getFields() { |
67 | $fields = [ |
68 | StatementsField::NAME => new StatementsField( |
69 | $this->propertyDataTypeLookup, |
70 | $this->propertyIds, |
71 | $this->indexedTypes, |
72 | $this->excludedIds, |
73 | $this->searchIndexDataFormatters |
74 | ), |
75 | StatementCountField::NAME => new StatementCountField(), |
76 | ]; |
77 | if ( $this->allowedQualifierPropertyIdsForQuantityStatements ) { |
78 | $fields[StatementQuantityField::NAME] = new StatementQuantityField( |
79 | $this->propertyDataTypeLookup, |
80 | $this->propertyIds, |
81 | $this->indexedTypes, |
82 | $this->excludedIds, |
83 | $this->searchIndexDataFormatters, |
84 | $this->allowedQualifierPropertyIdsForQuantityStatements |
85 | ); |
86 | } |
87 | return $fields; |
88 | } |
89 | |
90 | /** |
91 | * Factory to create StatementProviderFieldDefinitions from configs |
92 | * @param PropertyDataTypeLookup $propertyDataTypeLookup |
93 | * @param callable[] $searchIndexDataFormatters |
94 | * @param SettingsArray $settings |
95 | * @return StatementProviderFieldDefinitions |
96 | */ |
97 | public static function newFromSettings( |
98 | PropertyDataTypeLookup $propertyDataTypeLookup, |
99 | array $searchIndexDataFormatters, |
100 | SettingsArray $settings |
101 | ) { |
102 | return new static( $propertyDataTypeLookup, $searchIndexDataFormatters, |
103 | $settings->getSetting( 'searchIndexProperties' ), |
104 | $settings->getSetting( 'searchIndexTypes' ), |
105 | $settings->getSetting( 'searchIndexPropertiesExclude' ), |
106 | $settings->getSetting( 'searchIndexQualifierPropertiesForQuantity' ) |
107 | ); |
108 | } |
109 | |
110 | } |