Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| StatementProviderFieldDefinitions | |
0.00% |
0 / 37 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
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 | * @var ?callable |
| 22 | */ |
| 23 | private $statementProvider; |
| 24 | |
| 25 | /** |
| 26 | * @param DataTypeFactory $dataTypeFactory |
| 27 | * @param PropertyDataTypeLookup $propertyDataTypeLookup |
| 28 | * @param callable[] $searchIndexDataFormatters |
| 29 | * @param string[] $propertyIds List of properties to index |
| 30 | * @param array $indexedTypes |
| 31 | * @param array $excludedIds |
| 32 | * @param array $allowedQualifierPropertyIdsForQuantityStatements |
| 33 | * @param LoggerInterface|null $logger |
| 34 | * @param callable|null $statementProvider |
| 35 | */ |
| 36 | public function __construct( |
| 37 | private readonly DataTypeFactory $dataTypeFactory, |
| 38 | private readonly PropertyDataTypeLookup $propertyDataTypeLookup, |
| 39 | private readonly array $searchIndexDataFormatters, |
| 40 | private readonly array $propertyIds, |
| 41 | private readonly array $indexedTypes, |
| 42 | private readonly array $excludedIds, |
| 43 | private readonly array $allowedQualifierPropertyIdsForQuantityStatements, |
| 44 | private readonly ?LoggerInterface $logger = null, |
| 45 | ?callable $statementProvider = null, |
| 46 | ) { |
| 47 | $this->statementProvider = $statementProvider; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get the list of definitions |
| 52 | * @return WikibaseIndexField[] key is field name, value is WikibaseIndexField |
| 53 | */ |
| 54 | public function getFields() { |
| 55 | $fields = [ |
| 56 | StatementsField::NAME => new StatementsField( |
| 57 | $this->dataTypeFactory, |
| 58 | $this->propertyDataTypeLookup, |
| 59 | $this->propertyIds, |
| 60 | $this->indexedTypes, |
| 61 | $this->excludedIds, |
| 62 | $this->searchIndexDataFormatters, |
| 63 | $this->logger, |
| 64 | $this->statementProvider |
| 65 | ), |
| 66 | StatementCountField::NAME => new StatementCountField(), |
| 67 | ]; |
| 68 | if ( $this->allowedQualifierPropertyIdsForQuantityStatements ) { |
| 69 | $fields[StatementQuantityField::NAME] = new StatementQuantityField( |
| 70 | $this->dataTypeFactory, |
| 71 | $this->propertyDataTypeLookup, |
| 72 | $this->propertyIds, |
| 73 | $this->indexedTypes, |
| 74 | $this->excludedIds, |
| 75 | $this->searchIndexDataFormatters, |
| 76 | $this->allowedQualifierPropertyIdsForQuantityStatements, |
| 77 | $this->logger |
| 78 | ); |
| 79 | } |
| 80 | return $fields; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Factory to create StatementProviderFieldDefinitions from configs |
| 85 | * @param DataTypeFactory $dataTypeFactory |
| 86 | * @param PropertyDataTypeLookup $propertyDataTypeLookup |
| 87 | * @param callable[] $searchIndexDataFormatters |
| 88 | * @param SettingsArray $settings |
| 89 | * @param LoggerInterface|null $logger |
| 90 | * @param ?callable $statementProvider |
| 91 | * @return StatementProviderFieldDefinitions |
| 92 | */ |
| 93 | public static function newFromSettings( |
| 94 | DataTypeFactory $dataTypeFactory, |
| 95 | PropertyDataTypeLookup $propertyDataTypeLookup, |
| 96 | array $searchIndexDataFormatters, |
| 97 | SettingsArray $settings, |
| 98 | ?LoggerInterface $logger = null, |
| 99 | ?callable $statementProvider = null |
| 100 | ): self { |
| 101 | return new static( |
| 102 | $dataTypeFactory, |
| 103 | $propertyDataTypeLookup, |
| 104 | $searchIndexDataFormatters, |
| 105 | $settings->getSetting( 'searchIndexProperties' ), |
| 106 | $settings->getSetting( 'searchIndexTypes' ), |
| 107 | $settings->getSetting( 'searchIndexPropertiesExclude' ), |
| 108 | $settings->getSetting( 'searchIndexQualifierPropertiesForQuantity' ), |
| 109 | $logger, |
| 110 | $statementProvider |
| 111 | ); |
| 112 | } |
| 113 | |
| 114 | } |