Smalyshev has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/334019 )
Change subject: [WIP] Generalize field definitions for Items and Properties ...................................................................... [WIP] Generalize field definitions for Items and Properties NOTE: Labels & descriptions not handled yet here, this will be next patch. Change-Id: I781113f489267b092998a27c4ed76240db20f9ac NOTE: The change in EntityHandler will require updating MediaInfo handler too. --- M repo/includes/Content/EntityHandler.php M repo/includes/Content/ItemHandler.php M repo/includes/Content/PropertyHandler.php A repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php A repo/includes/Search/Elastic/Fields/FieldDefinitions.php A repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php A repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php A repo/includes/Search/Elastic/Fields/PropertyFieldDefinitions.php D repo/includes/Search/Elastic/Fields/WikibaseFieldDefinitions.php M repo/includes/Search/Elastic/Fields/WikibaseNumericField.php M repo/includes/WikibaseRepo.php 11 files changed, 255 insertions(+), 29 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/19/334019/1 diff --git a/repo/includes/Content/EntityHandler.php b/repo/includes/Content/EntityHandler.php index 2ca307c..ab6ef5c 100644 --- a/repo/includes/Content/EntityHandler.php +++ b/repo/includes/Content/EntityHandler.php @@ -29,6 +29,7 @@ use Wikibase\EntityContent; use Wikibase\Lib\Store\EntityContentDataCodec; use Wikibase\Repo\Diff\EntityContentDiffView; +use Wikibase\Repo\Search\Elastic\Fields\FieldDefinitions; use Wikibase\Repo\Search\Elastic\Fields\WikibaseFieldDefinitions; use Wikibase\Repo\Store\EntityPerPage; use Wikibase\Repo\Validators\EntityConstraintProvider; @@ -55,6 +56,9 @@ * to parser output. */ const PARSER_VERSION = 3; + /** + * @var FieldDefinitions + */ protected $fieldDefinitions; /** @@ -101,12 +105,12 @@ * @param EntityConstraintProvider $constraintProvider * @param ValidatorErrorLocalizer $errorLocalizer * @param EntityIdParser $entityIdParser + * @param FieldDefinitions $fieldDefinitions * @param callable|null $legacyExportFormatDetector Callback to determine whether a serialized * blob needs to be re-serialized on export. The callback must take two parameters, * the blob an the serialization format. It must return true if re-serialization is needed. * False positives are acceptable, false negatives are not. * - * @throws InvalidArgumentException */ public function __construct( $modelId, @@ -116,6 +120,7 @@ EntityConstraintProvider $constraintProvider, ValidatorErrorLocalizer $errorLocalizer, EntityIdParser $entityIdParser, + FieldDefinitions $fieldDefinitions, $legacyExportFormatDetector = null ) { $formats = $contentCodec->getSupportedFormats(); @@ -133,8 +138,7 @@ $this->errorLocalizer = $errorLocalizer; $this->entityIdParser = $entityIdParser; $this->legacyExportFormatDetector = $legacyExportFormatDetector; - // FIXME: convert to DI, will be in the next patch - $this->fieldDefinitions = new WikibaseFieldDefinitions(); + $this->fieldDefinitions = $fieldDefinitions; } /** diff --git a/repo/includes/Content/ItemHandler.php b/repo/includes/Content/ItemHandler.php index 97e4d44..34b0daa 100644 --- a/repo/includes/Content/ItemHandler.php +++ b/repo/includes/Content/ItemHandler.php @@ -18,6 +18,7 @@ use Wikibase\Lib\Store\EntityContentDataCodec; use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory; use Wikibase\Lib\Store\SiteLinkStore; +use Wikibase\Repo\Search\Elastic\Fields\ItemFieldDefinitions; use Wikibase\Repo\Store\EntityPerPage; use Wikibase\Repo\Validators\EntityConstraintProvider; use Wikibase\Repo\Validators\ValidatorErrorLocalizer; @@ -61,6 +62,7 @@ * @param SiteLinkStore $siteLinkStore * @param EntityIdLookup $entityIdLookup * @param LanguageFallbackLabelDescriptionLookupFactory $labelLookupFactory + * @param ItemFieldDefinitions $itemFieldDefinitions * @param callable|null $legacyExportFormatDetector */ public function __construct( @@ -73,6 +75,7 @@ SiteLinkStore $siteLinkStore, EntityIdLookup $entityIdLookup, LanguageFallbackLabelDescriptionLookupFactory $labelLookupFactory, + ItemFieldDefinitions $itemFieldDefinitions, $legacyExportFormatDetector = null ) { parent::__construct( @@ -83,6 +86,7 @@ $constraintProvider, $errorLocalizer, $entityIdParser, + $itemFieldDefinitions, $legacyExportFormatDetector ); diff --git a/repo/includes/Content/PropertyHandler.php b/repo/includes/Content/PropertyHandler.php index 55f3634..2ba3126 100644 --- a/repo/includes/Content/PropertyHandler.php +++ b/repo/includes/Content/PropertyHandler.php @@ -18,6 +18,7 @@ use Wikibase\PropertyContent; use Wikibase\PropertyInfoBuilder; use Wikibase\Lib\Store\PropertyInfoStore; +use Wikibase\Repo\Search\Elastic\Fields\PropertyFieldDefinitions; use Wikibase\Repo\Store\EntityPerPage; use Wikibase\Repo\Validators\EntityConstraintProvider; use Wikibase\Repo\Validators\ValidatorErrorLocalizer; @@ -75,7 +76,9 @@ * @param LanguageFallbackLabelDescriptionLookupFactory $labelLookupFactory * @param PropertyInfoStore $infoStore * @param PropertyInfoBuilder $propertyInfoBuilder + * @param PropertyFieldDefinitions $propertyFieldDefinitions * @param callable|null $legacyExportFormatDetector + * @internal param PropertyFieldDefinitions $itemFieldDefinitions */ public function __construct( EntityPerPage $entityPerPage, @@ -88,6 +91,7 @@ LanguageFallbackLabelDescriptionLookupFactory $labelLookupFactory, PropertyInfoStore $infoStore, PropertyInfoBuilder $propertyInfoBuilder, + PropertyFieldDefinitions $propertyFieldDefinitions, $legacyExportFormatDetector = null ) { parent::__construct( @@ -98,6 +102,7 @@ $constraintProvider, $errorLocalizer, $entityIdParser, + $propertyFieldDefinitions, $legacyExportFormatDetector ); diff --git a/repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php b/repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php new file mode 100644 index 0000000..6d07ed2 --- /dev/null +++ b/repo/includes/Search/Elastic/Fields/DescriptionProviderFieldDefinitions.php @@ -0,0 +1,33 @@ +<?php +namespace Wikibase\Repo\Search\Elastic\Fields; + +/** + * + * Definitions for any entity that has descriptions. + */ +class DescriptionsProviderFieldDefinitions implements FieldDefinitions { + + /** + * @var string[] + */ + private $languageCodes; + + /** + * @param string[] $languageCodes + */ + public function __construct( array $languageCodes ) { + $this->languageCodes = $languageCodes; + } + + /** + * @return array + */ + public function getFields() { + $fields = []; + + // TODO: nothing for now, will add later + + return $fields; + } + +} diff --git a/repo/includes/Search/Elastic/Fields/FieldDefinitions.php b/repo/includes/Search/Elastic/Fields/FieldDefinitions.php new file mode 100644 index 0000000..2b266ef --- /dev/null +++ b/repo/includes/Search/Elastic/Fields/FieldDefinitions.php @@ -0,0 +1,17 @@ +<?php +namespace Wikibase\Repo\Search\Elastic\Fields; + +/** + * This is a collection of field definitions. + * This interface should be implemented by specific definition + * classes which know which fields they deal with. + * @package Wikibase\Repo\Search\Elastic\Fields + */ +interface FieldDefinitions { + + /** + * Get the list of definitions, key is name, value is SearchIndexField + * @return SearchIndexField[] + */ + public function getFields(); +} \ No newline at end of file diff --git a/repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php b/repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php new file mode 100644 index 0000000..e850271 --- /dev/null +++ b/repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php @@ -0,0 +1,54 @@ +<?php +namespace Wikibase\Repo\Search\Elastic\Fields; + +/** + * Search fields that are used for items. + * @package Wikibase\Repo\Search\Elastic\Fields + */ +class ItemFieldDefinitions implements FieldDefinitions { + + /** + * @var LabelsProviderFieldDefinitions + */ + private $labelsProviderFieldDefinitions; + + /** + * @var DescriptionsProviderFieldDefinitions + */ + private $descriptionsProviderFieldDefinitions; + + /** + * @param LabelsProviderFieldDefinitions $labelsProviderFieldDefinitions + * @param DescriptionsProviderFieldDefinitions $descriptionsProviderFieldDefinitions + */ + public function __construct( + LabelsProviderFieldDefinitions $labelsProviderFieldDefinitions, + DescriptionsProviderFieldDefinitions $descriptionsProviderFieldDefinitions + ) { + $this->labelsProviderFieldDefinitions = $labelsProviderFieldDefinitions; + $this->descriptionsProviderFieldDefinitions = $descriptionsProviderFieldDefinitions; + } + + /** + * @return SearchIndexField[] + */ + public function getFields() { + /* + * Items have: + * - labels + * - descriptions + * - link count + * - statement count + */ + $fields = array_merge( + $this->labelsProviderFieldDefinitions->getFields(), + $this->descriptionsProviderFieldDefinitions->getFields() + ); + + $fields['sitelink_count'] = new SiteLinkCountField(); + $fields['statement_count'] = new StatementCountField(); + + return $fields; + } + +} \ No newline at end of file diff --git a/repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php b/repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php new file mode 100644 index 0000000..217a6e0 --- /dev/null +++ b/repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php @@ -0,0 +1,43 @@ +<?php +namespace Wikibase\Repo\Search\Elastic\Fields; + +/** + * Definitions for any entity that has labels. + */ +class LabelsProviderFieldDefinitions implements FieldDefinitions { + + /** + * @var string[] + */ + private $languageCodes; + + /** + * @param string[] $languageCodes + */ + public function __construct( array $languageCodes ) { + $this->languageCodes = $languageCodes; + } + + /** + * @return SearchIndexField[] + */ + public function getFields() { + + $fields = $this->getLabelFields(); + $fields['label_count'] = new LabelCountField(); + + return $fields; + } + + /** + * @return SearchIndexField[] + */ + private function getLabelFields() { + $fields = []; + + // TODO: next patch will have actual label fields + + return $fields; + } + +} diff --git a/repo/includes/Search/Elastic/Fields/PropertyFieldDefinitions.php b/repo/includes/Search/Elastic/Fields/PropertyFieldDefinitions.php new file mode 100644 index 0000000..11c8164 --- /dev/null +++ b/repo/includes/Search/Elastic/Fields/PropertyFieldDefinitions.php @@ -0,0 +1,52 @@ +<?php +namespace Wikibase\Repo\Search\Elastic\Fields; + +/** + * Search fields that are used for properties. + * @package Wikibase\Repo\Search\Elastic\Fields + */ +class PropertyFieldDefinitions implements FieldDefinitions { + + /** + * @var LabelsProviderFieldDefinitions + */ + private $labelsProviderFieldDefinitions; + + /** + * @var DescriptionsProviderFieldDefinitions + */ + private $descriptionsProviderFieldDefinitions; + + /** + * @param LabelsProviderFieldDefinitions $labelsProviderFieldDefinitions + * @param DescriptionsProviderFieldDefinitions $descriptionsProviderFieldDefinitions + */ + public function __construct( + LabelsProviderFieldDefinitions $labelsProviderFieldDefinitions, + DescriptionsProviderFieldDefinitions $descriptionsProviderFieldDefinitions + ) { + $this->labelsProviderFieldDefinitions = $labelsProviderFieldDefinitions; + $this->descriptionsProviderFieldDefinitions = $descriptionsProviderFieldDefinitions; + } + + /** + * @return SearchIndexField[] + */ + public function getFields() { + /* + * Properties have: + * - labels + * - descriptions + * - statement count + */ + $fields = array_merge( + $this->labelsProviderFieldDefinitions->getFields(), + $this->descriptionsProviderFieldDefinitions->getFields() + ); + + $fields['statement_count'] = new StatementCountField(); + + return $fields; + } + +} \ No newline at end of file diff --git a/repo/includes/Search/Elastic/Fields/WikibaseFieldDefinitions.php b/repo/includes/Search/Elastic/Fields/WikibaseFieldDefinitions.php deleted file mode 100644 index e243642..0000000 --- a/repo/includes/Search/Elastic/Fields/WikibaseFieldDefinitions.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -namespace Wikibase\Repo\Search\Elastic\Fields; - -/** - * @license GPL-2.0+ - * @author Katie Filbert < aude.w...@gmail.com > - */ -class WikibaseFieldDefinitions { - - /** - * @return SearchIndexField[] Array key is field name. - */ - public function getFields() { - $fields = array( - 'label_count' => new LabelCountField(), - 'sitelink_count' => new SiteLinkCountField(), - 'statement_count' => new StatementCountField() - ); - - return $fields; - } - -} diff --git a/repo/includes/Search/Elastic/Fields/WikibaseNumericField.php b/repo/includes/Search/Elastic/Fields/WikibaseNumericField.php index 4715153..ddc8599 100644 --- a/repo/includes/Search/Elastic/Fields/WikibaseNumericField.php +++ b/repo/includes/Search/Elastic/Fields/WikibaseNumericField.php @@ -4,8 +4,7 @@ use SearchEngine; /** - * Generic numeric field - * @package Wikibase\Repo\Search\Elastic\Fields + * Generic numeric field. */ abstract class WikibaseNumericField implements SearchIndexField { diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index a174c21..edbca26 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -83,6 +83,10 @@ use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\Lib\Store\EntityStore; use Wikibase\Lib\Store\EntityStoreWatcher; +use Wikibase\Repo\Search\Elastic\Fields\DescriptionsProviderFieldDefinitions; +use Wikibase\Repo\Search\Elastic\Fields\ItemFieldDefinitions; +use Wikibase\Repo\Search\Elastic\Fields\LabelsProviderFieldDefinitions; +use Wikibase\Repo\Search\Elastic\Fields\PropertyFieldDefinitions; use Wikibase\Repo\Store\EntityTitleStoreLookup; use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory; use Wikibase\Lib\Store\WikiPagePropertyOrderProvider; @@ -1355,10 +1359,44 @@ $siteLinkStore, $this->getEntityIdLookup(), $this->getLanguageFallbackLabelDescriptionLookupFactory(), + $this->getItemFieldDefinitions(), $legacyFormatDetector ); return $handler; + } + + /** + * @return LabelsProviderFieldDefinitions + */ + public function getLabelProviderDefinitions() { + return new LabelsProviderFieldDefinitions( $this->getTermsLanguages()->getLanguages() ); + } + + /** + * @return DescriptionsProviderFieldDefinitions + */ + public function getDescriptionProviderDefinitions() { + return new DescriptionsProviderFieldDefinitions( $this->getTermsLanguages() + ->getLanguages() ); + } + + /** + * @return ItemFieldDefinitions + */ + private function getItemFieldDefinitions() { + return new ItemFieldDefinitions( + $this->getLabelProviderDefinitions(), $this->getDescriptionProviderDefinitions() + ); + } + + /** + * @return PropertyFieldDefinitions + */ + private function getPropertyFieldDefinitions() { + return new PropertyFieldDefinitions( + $this->getLabelProviderDefinitions(), $this->getDescriptionProviderDefinitions() + ); } /** @@ -1385,6 +1423,7 @@ $this->getLanguageFallbackLabelDescriptionLookupFactory(), $propertyInfoStore, $propertyInfoBuilder, + $this->getPropertyFieldDefinitions(), $legacyFormatDetector ); -- To view, visit https://gerrit.wikimedia.org/r/334019 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I781113f489267b092998a27c4ed76240db20f9ac Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Smalyshev <smalys...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits