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