Daniel Kinzler has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/222268

Change subject: SearchEntities return 'aliases' when not same as label
......................................................................

SearchEntities return 'aliases' when not same as label

This partially reverts:
Ia5eaa1ba74a4f6fbc19cef1caf7f7dc42bb70016

The only reason we still call these aliases is to
avoid breaking things.
I have left a small comment in the code explaning
what is happeneing and I have also updated the
doc / description of the api module.

Bug: T104273
Change-Id: I2c0f2748518f84aad6b9818cbd81b58a39f88cf6
---
M repo/i18n/en.json
M repo/includes/api/SearchEntities.php
M repo/tests/phpunit/includes/api/SearchEntitiesTest.php
3 files changed, 12 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/68/222268/1

diff --git a/repo/i18n/en.json b/repo/i18n/en.json
index 8a8067eb..73ced8f 100644
--- a/repo/i18n/en.json
+++ b/repo/i18n/en.json
@@ -563,14 +563,14 @@
        "apihelp-wbremovereferences-param-statement": "A GUID identifying the 
statement for which a reference is being set",
        "apihelp-wbremovereferences-param-references": "The hashes of the 
references that should be removed",
        "apihelp-wbremovereferences-example-1": "Remove reference with hash 
\"455481eeac76e6a8af71a6b493c073d54788e7e9\" from claim with GUID of 
\"Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0F\"",
-       "apihelp-wbsearchentities-description": "Searches for entities.",
+       "apihelp-wbsearchentities-description": "Searches for entities using 
labels and aliases.\nReturns a label and description for the entity in the user 
language if possible.\nReturns details of the matched term.\nThe matched term 
text is also present in the aliases key if different from the display label.",
        "apihelp-wbsearchentities-param-search": "Search for this text.",
        "apihelp-wbsearchentities-param-language": "Search in this language.",
        "apihelp-wbsearchentities-param-type": "Search for this type of 
entity.",
        "apihelp-wbsearchentities-param-limit": "Maximal number of results",
        "apihelp-wbsearchentities-param-continue": "Offset where to continue a 
search",
        "apihelp-wbsearchentities-example-1": "Search for \"abc\" in English 
language, with defaults for type and limit",
-       "apihelp-wbsearchentities-example-2": "Search for \"abc\" in English 
language with a limit of 50",
+       "apihelp-wbsearchentities-example-2": "Search git diff for \"abc\" in 
English language with a limit of 50",
        "apihelp-wbsearchentities-example-3": "Search for \"alphabet\" in 
English language for type property",
        "apihelp-wbsetaliases-description": "Sets the aliases for a Wikibase 
entity.",
        "apihelp-wbsetaliases-param-id": "The identifier for the entity, 
including the prefix.\nUse either 'id' or 'site' and 'title' together.",
diff --git a/repo/includes/api/SearchEntities.php 
b/repo/includes/api/SearchEntities.php
index c54e7fb..5a990dc 100644
--- a/repo/includes/api/SearchEntities.php
+++ b/repo/includes/api/SearchEntities.php
@@ -188,11 +188,17 @@
                        } else {
                                /** @var Term $matchedTerm */
                                $matchedTerm = 
$match[TermIndexSearchInteractor::MATCHEDTERM_KEY];
+                               $matchedTermText = $matchedTerm->getText();
                                $entry['match']['language'] = 
$matchedTerm->getLanguageCode();
-                               $entry['match']['text'] = 
$matchedTerm->getText();
+                               $entry['match']['text'] = $matchedTermText;
 
-                               if ( $match['matchedTermType'] === 'alias' ) {
-                                       $entry['aliases'] = array( 
$matchedTerm->getText() );
+                               /**
+                                * Add matched terms to the aliases key in the 
result to give some context for the matched Term
+                                * if the matched term is different to the 
alias.
+                                * XXX: This appears odd but is used in the UI 
/ Entity suggesters
+                                */
+                               if ( !array_key_exists( 'label', $entry ) || 
$matchedTermText != $entry['label'] ) {
+                                       $entry['aliases'] = array( 
$matchedTermText );
                                }
                        }
                        $entries[] = $entry;
diff --git a/repo/tests/phpunit/includes/api/SearchEntitiesTest.php 
b/repo/tests/phpunit/includes/api/SearchEntitiesTest.php
index c5d9acb..e3b1217 100644
--- a/repo/tests/phpunit/includes/api/SearchEntitiesTest.php
+++ b/repo/tests/phpunit/includes/api/SearchEntitiesTest.php
@@ -249,6 +249,7 @@
                        'url' => 'http://fullTitleUrl',
                        TermIndexEntry::TYPE_LABEL => 'FooHeHe',
                        TermIndexEntry::TYPE_DESCRIPTION => 'FooHeHe en 
description',
+                       'aliases' => array( 'Fooooo' ),
                        'match' => array(
                                'type' => 'label',
                                'language' => 'en-gb',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2c0f2748518f84aad6b9818cbd81b58a39f88cf6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.26wmf12
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>

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

Reply via email to