jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/397852 )

Change subject: Extract names of search fields as constants
......................................................................


Extract names of search fields as constants

The mapping is currently configured by constructing an array where the
key is the field name. The field itself has a name declared. Extract
the name literals as constants to avoid inconsistencies between the
name declared in the mapping array and the name of the field.
The name of the field is not very important but is used is some
circumtances such as the similarity configuration.

This also fixes an inconsistency for the "descriptions" field which
was exposed as "descriptions" but named "description".

Bug: T182293
Change-Id: I4e79bf1a389beec423b07e34082c4b8920e54af0
---
M repo/includes/Search/Elastic/Fields/AllLabelsField.php
M repo/includes/Search/Elastic/Fields/DescriptionsField.php
M repo/includes/Search/Elastic/Fields/DescriptionsProviderFieldDefinitions.php
M repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php
M repo/includes/Search/Elastic/Fields/LabelCountField.php
M repo/includes/Search/Elastic/Fields/LabelsField.php
M repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php
M repo/includes/Search/Elastic/Fields/SiteLinkCountField.php
M repo/includes/Search/Elastic/Fields/StatementCountField.php
M repo/includes/Search/Elastic/Fields/StatementProviderFieldDefinitions.php
M repo/includes/Search/Elastic/Fields/StatementsField.php
11 files changed, 47 insertions(+), 11 deletions(-)

Approvals:
  Smalyshev: Looks good to me, approved
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, but someone else must approve



diff --git a/repo/includes/Search/Elastic/Fields/AllLabelsField.php 
b/repo/includes/Search/Elastic/Fields/AllLabelsField.php
index cdce12c..767c505 100644
--- a/repo/includes/Search/Elastic/Fields/AllLabelsField.php
+++ b/repo/includes/Search/Elastic/Fields/AllLabelsField.php
@@ -13,8 +13,13 @@
  */
 class AllLabelsField extends TermIndexField {
 
+       /**
+        * Field name
+        */
+       const NAME = 'labels_all';
+
        public function __construct() {
-               parent::__construct( "", \SearchIndexField::INDEX_TYPE_TEXT );
+               parent::__construct( static::NAME, 
\SearchIndexField::INDEX_TYPE_TEXT );
        }
 
        /**
diff --git a/repo/includes/Search/Elastic/Fields/DescriptionsField.php 
b/repo/includes/Search/Elastic/Fields/DescriptionsField.php
index 40c6217..97b18bf 100644
--- a/repo/includes/Search/Elastic/Fields/DescriptionsField.php
+++ b/repo/includes/Search/Elastic/Fields/DescriptionsField.php
@@ -16,6 +16,11 @@
 class DescriptionsField extends TermIndexField {
 
        /**
+        * Field name
+        */
+       const NAME = 'descriptions';
+
+       /**
         * List of available languages
         * @var string[]
         */
@@ -31,7 +36,7 @@
         */
        public function __construct( array $languages, array $searchSettings ) {
                $this->languages = $languages;
-               parent::__construct( "description", 
\SearchIndexField::INDEX_TYPE_NESTED );
+               parent::__construct( static::NAME, 
\SearchIndexField::INDEX_TYPE_NESTED );
                $this->searchSettings = $searchSettings;
        }
 
diff --git 
a/repo/includes/Search/Elastic/Fields/DescriptionsProviderFieldDefinitions.php 
b/repo/includes/Search/Elastic/Fields/DescriptionsProviderFieldDefinitions.php
index 8dd8a96..cf99117 100644
--- 
a/repo/includes/Search/Elastic/Fields/DescriptionsProviderFieldDefinitions.php
+++ 
b/repo/includes/Search/Elastic/Fields/DescriptionsProviderFieldDefinitions.php
@@ -33,7 +33,7 @@
         */
        public function getFields() {
                return [
-                       'descriptions' => new DescriptionsField( 
$this->languageCodes, $this->searchSettings ),
+                       DescriptionsField::NAME => new DescriptionsField( 
$this->languageCodes, $this->searchSettings ),
                ];
        }
 
diff --git a/repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php 
b/repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php
index fe7d4d1..8c8ff69 100644
--- a/repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php
+++ b/repo/includes/Search/Elastic/Fields/ItemFieldDefinitions.php
@@ -32,7 +32,7 @@
                        $fields = array_merge( $fields, 
$definitions->getFields() );
                }
 
-               $fields['sitelink_count'] = new SiteLinkCountField();
+               $fields[SiteLinkCountField::NAME] = new SiteLinkCountField();
 
                return $fields;
        }
diff --git a/repo/includes/Search/Elastic/Fields/LabelCountField.php 
b/repo/includes/Search/Elastic/Fields/LabelCountField.php
index d717351..76ffe45 100644
--- a/repo/includes/Search/Elastic/Fields/LabelCountField.php
+++ b/repo/includes/Search/Elastic/Fields/LabelCountField.php
@@ -12,6 +12,11 @@
 class LabelCountField extends WikibaseNumericField {
 
        /**
+        * Field name
+        */
+       const NAME = 'label_count';
+
+       /**
         * @see SearchIndexField::getFieldData
         *
         * @param EntityDocument $entity
diff --git a/repo/includes/Search/Elastic/Fields/LabelsField.php 
b/repo/includes/Search/Elastic/Fields/LabelsField.php
index b48c45d..48fe4d1 100644
--- a/repo/includes/Search/Elastic/Fields/LabelsField.php
+++ b/repo/includes/Search/Elastic/Fields/LabelsField.php
@@ -16,6 +16,11 @@
 class LabelsField extends TermIndexField {
 
        /**
+        * Field name
+        */
+       const NAME = "labels";
+
+       /**
         * List of available languages
         * @var string[]
         */
@@ -27,7 +32,7 @@
         */
        public function __construct( $languages ) {
                $this->languages = $languages;
-               parent::__construct( "labels", 
\SearchIndexField::INDEX_TYPE_NESTED );
+               parent::__construct( self::NAME, 
\SearchIndexField::INDEX_TYPE_NESTED );
        }
 
        /**
diff --git 
a/repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php 
b/repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php
index c0cc434..c246635 100644
--- a/repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php
+++ b/repo/includes/Search/Elastic/Fields/LabelsProviderFieldDefinitons.php
@@ -27,9 +27,9 @@
         */
        public function getFields() {
                return [
-                       'label_count' => new LabelCountField(),
-                       'labels' => new LabelsField( $this->languageCodes ),
-                       'labels_all' => new AllLabelsField(),
+                       LabelCountField::NAME => new LabelCountField(),
+                       LabelsField::NAME => new LabelsField( 
$this->languageCodes ),
+                       AllLabelsField::NAME => new AllLabelsField(),
                ];
        }
 
diff --git a/repo/includes/Search/Elastic/Fields/SiteLinkCountField.php 
b/repo/includes/Search/Elastic/Fields/SiteLinkCountField.php
index 4625e06..03c773e 100644
--- a/repo/includes/Search/Elastic/Fields/SiteLinkCountField.php
+++ b/repo/includes/Search/Elastic/Fields/SiteLinkCountField.php
@@ -12,6 +12,12 @@
 class SiteLinkCountField extends WikibaseNumericField {
 
        /**
+        * Field name
+        * @var string
+        */
+       const NAME = 'sitelink_count';
+
+       /**
         * @see SearchIndexField::getFieldData
         *
         * @param EntityDocument $entity
diff --git a/repo/includes/Search/Elastic/Fields/StatementCountField.php 
b/repo/includes/Search/Elastic/Fields/StatementCountField.php
index 308bc3e..8ce63f7 100644
--- a/repo/includes/Search/Elastic/Fields/StatementCountField.php
+++ b/repo/includes/Search/Elastic/Fields/StatementCountField.php
@@ -12,6 +12,11 @@
 class StatementCountField extends WikibaseNumericField {
 
        /**
+        * Field name
+        */
+       const NAME = 'statement_count';
+
+       /**
         * @see SearchIndexField::getFieldData
         *
         * @param EntityDocument $entity
diff --git 
a/repo/includes/Search/Elastic/Fields/StatementProviderFieldDefinitions.php 
b/repo/includes/Search/Elastic/Fields/StatementProviderFieldDefinitions.php
index 22ea44f..e425cf9 100644
--- a/repo/includes/Search/Elastic/Fields/StatementProviderFieldDefinitions.php
+++ b/repo/includes/Search/Elastic/Fields/StatementProviderFieldDefinitions.php
@@ -36,11 +36,11 @@
         */
        public function getFields() {
                return [
-                       'statement_keywords' => new StatementsField(
+                       StatementsField::NAME => new StatementsField(
                                $this->propertyIds,
                                $this->searchIndexDataFormatters
                        ),
-                       'statement_count' => new StatementCountField(),
+                       StatementCountField::NAME => new StatementCountField(),
                ];
        }
 
diff --git a/repo/includes/Search/Elastic/Fields/StatementsField.php 
b/repo/includes/Search/Elastic/Fields/StatementsField.php
index 4d265cc..89a3095 100644
--- a/repo/includes/Search/Elastic/Fields/StatementsField.php
+++ b/repo/includes/Search/Elastic/Fields/StatementsField.php
@@ -21,6 +21,11 @@
 class StatementsField extends SearchIndexFieldDefinition implements 
WikibaseIndexField {
 
        /**
+        * Field name
+        */
+       const NAME = 'statement_keywords';
+
+       /**
         * String which separates property from value in statement 
representation.
         * Should be the string that is:
         * - Not part of property ID serialization
@@ -43,7 +48,7 @@
         * @param callable[] $searchIndexDataFormatters
         */
        public function __construct( array $propertyIds, array 
$searchIndexDataFormatters ) {
-               parent::__construct( '', SearchIndexField::INDEX_TYPE_KEYWORD );
+               parent::__construct( static::NAME, 
SearchIndexField::INDEX_TYPE_KEYWORD );
 
                $this->propertyIds = array_flip( $propertyIds );
                $this->searchIndexDataFormatters = $searchIndexDataFormatters;

-- 
To view, visit https://gerrit.wikimedia.org/r/397852
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4e79bf1a389beec423b07e34082c4b8920e54af0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to