Skip to content

Commit 064fbc6

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "Search: Rename result label field to display-label"
2 parents eb15cc4 + 10ea85d commit 064fbc6

File tree

8 files changed

+40
-43
lines changed

8 files changed

+40
-43
lines changed

repo/domains/search/specs/global/responses.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
"results": [
4242
{
4343
"id": "Q123",
44-
"label": { "language": "en", "value": "potato" },
44+
"display-label": { "language": "en", "value": "potato" },
4545
"description": { "language": "en", "value": "staple food" },
4646
"match": { "type": "label", "language": "en", "text": "potato" }
4747
},
4848
{
4949
"id": "Q234",
50-
"label": { "language": "en", "value": "potato" },
50+
"display-label": { "language": "en", "value": "potato" },
5151
"description": { "language": "en", "value": "species of plant" },
5252
"match": { "type": "label", "language": "en", "text": "potato" }
5353
}
@@ -65,13 +65,13 @@
6565
"results": [
6666
{
6767
"id": "P123",
68-
"label": { "language": "en", "value": "taxon name" },
68+
"display-label": { "language": "en", "value": "taxon name" },
6969
"description": { "language": "en", "value": "scientific name of a taxon" },
7070
"match": { "type": "label", "language": "en", "text": "taxon" }
7171
},
7272
{
7373
"id": "P234",
74-
"label": { "language": "en", "value": "taxon rank" },
74+
"display-label": { "language": "en", "value": "taxon rank" },
7575
"description": { "language": "en", "value": "level in a taxonomic hierarchy" },
7676
"match": { "type": "label", "language": "en", "text": "taxon" }
7777
}

repo/domains/search/specs/global/schema-parts.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Label": {
2+
"DisplayLabel": {
33
"type": [ "object", "null" ],
44
"properties": {
55
"language": { "type": "string" },
@@ -34,12 +34,12 @@
3434
"type": "string",
3535
"pattern": "^Q[1-9]\\d{0,9}$"
3636
},
37-
"label": { "$ref": "#/Label" },
37+
"display-label": { "$ref": "#/DisplayLabel" },
3838
"description": { "$ref": "#/Description" },
3939
"match": { "$ref": "#/Match" }
4040
},
4141
"additionalProperties": false,
42-
"required": [ "id", "label", "description", "match" ]
42+
"required": [ "id", "display-label", "description", "match" ]
4343
},
4444
"SearchPropertyResult": {
4545
"type": "object",
@@ -48,12 +48,12 @@
4848
"type": "string",
4949
"pattern": "^P[1-9]\\d{0,9}$"
5050
},
51-
"label": { "$ref": "#/Label" },
51+
"display-label": { "$ref": "#/DisplayLabel" },
5252
"description": { "$ref": "#/Description" },
5353
"match": { "$ref": "#/Match" }
5454
},
5555
"additionalProperties": false,
56-
"required": [ "id", "label", "description", "match" ]
56+
"required": [ "id", "display-label", "description", "match" ]
5757
},
5858
"SearchItemResultList": {
5959
"type": "object",

repo/domains/search/src/Infrastructure/DataAccess/InLabelItemSearchEngine.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Wikibase\DataModel\Entity\Item;
66
use Wikibase\DataModel\Entity\ItemId;
7-
use Wikibase\DataModel\Term\TermTypes;
87
use Wikibase\Lib\Interactors\TermSearchResult;
98
use Wikibase\Repo\Domains\Search\Domain\Model\Description;
109
use Wikibase\Repo\Domains\Search\Domain\Model\ItemSearchResult;
@@ -34,10 +33,7 @@ public function searchItemByLabel( string $searchTerm, string $languageCode ): I
3433
fn( TermSearchResult $result ) => new ItemSearchResult(
3534
new ItemId( $result->getEntityId()->getSerialization() ),
3635

37-
$result->getDisplayLabel() &&
38-
// if an alias was matched and there is no label, don't use the alias as the label
39-
( $result->getMatchedTermType() !== TermTypes::TYPE_ALIAS ||
40-
!$result->getMatchedTerm()->equals( $result->getDisplayLabel() ) )
36+
$result->getDisplayLabel()
4137
? new Label( $result->getDisplayLabel()->getLanguageCode(), $result->getDisplayLabel()->getText() )
4238
: null,
4339
$result->getDisplayDescription() ?

repo/domains/search/src/Infrastructure/DataAccess/SqlTermStoreSearchEngine.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ public function __construct(
4040
public function searchItemByLabel( string $searchTerm, string $languageCode ): ItemSearchResults {
4141
return new ItemSearchResults( ...array_map(
4242
function ( TermIndexEntry $entry ) use ( $languageCode ) {
43+
$matchedTermAsLabel = new Label( $entry->getLanguage(), $entry->getText() );
4344
// if the matching entry is a label
44-
$label = $entry->getTermType() === TermTypes::TYPE_LABEL ?
45+
$itemLabel = $entry->getTermType() === TermTypes::TYPE_LABEL ?
4546
// then use it for the search result
46-
new Label( $entry->getLanguage(), $entry->getText() ) :
47+
$matchedTermAsLabel :
4748
// otherwise look up the item label in search language
4849
$this->termRetriever->getLabel( $entry->getEntityId(), $languageCode );
4950
return new ItemSearchResult(
5051
new ItemId( (string)$entry->getEntityId() ),
51-
$label,
52+
$itemLabel ?? $matchedTermAsLabel,
5253
$this->termRetriever->getDescription( $entry->getEntityId(), $languageCode ),
5354
new MatchedData( $entry->getTermType(), $entry->getLanguage(), $entry->getText() )
5455
);

repo/domains/search/src/RouteHandlers/SimpleItemSearchRouteHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private function formatResults( ItemSearchResults $results ): array {
142142
return array_map(
143143
fn( ItemSearchResult $result ) => [
144144
'id' => $result->getItemId()->getSerialization(),
145-
'label' => $result->getLabel() ? [
145+
'display-label' => $result->getLabel() ? [
146146
'language' => $result->getLabel()->getLanguageCode(),
147147
'value' => $result->getLabel()->getText(),
148148
] : null,

repo/domains/search/tests/mocha/api-testing/SimpleItemSearchTest.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ describe( 'Simple item search', () => {
6767
const item1Result = results.find( ( { id } ) => id === item1.id );
6868
assert.deepEqual( item1Result, {
6969
id: item1.id,
70-
label: { language, value: item1Label },
70+
'display-label': { language, value: item1Label },
7171
description: { language, value: item1Description },
7272
match: { type: 'label', language, text: item1Label }
7373
} );
7474

7575
const item2Result = results.find( ( { id } ) => id === itemWithoutDescription.id );
7676
assert.deepEqual( item2Result, {
7777
id: itemWithoutDescription.id,
78-
label: { language, value: item2Label },
78+
'display-label': { language, value: item2Label },
7979
description: null,
8080
match: { type: 'label', language, text: item2Label }
8181
} );
@@ -90,15 +90,15 @@ describe( 'Simple item search', () => {
9090
expect( response ).to.have.status( 200 );
9191
assert.deepEqual( response.body.results, [ {
9292
id: item1.id,
93-
label: { language, value: item1GermanLabel },
93+
'display-label': { language, value: item1GermanLabel },
9494
description: { language, value: item1GermanDescription },
9595
match: { type: 'label', language, text: item1GermanLabel }
9696
} ] );
9797
} );
9898

99-
it( 'finds item without a label', async () => {
99+
it( 'finds item without a label by alias', async () => {
100100
const language = 'en';
101-
const response = await newSearchRequest( language, englishTermMatchingAllItems )
101+
const response = await newSearchRequest( language, item3Alias )
102102
.assertValidRequest()
103103
.makeRequest();
104104

@@ -110,7 +110,7 @@ describe( 'Simple item search', () => {
110110
const itemResult = results.find( ( { id } ) => id === itemWithoutLabel.id );
111111
assert.deepEqual( itemResult, {
112112
id: itemWithoutLabel.id,
113-
label: null,
113+
'display-label': { language, value: item3Alias },
114114
description: { language, value: item3Description },
115115
match: { type: 'alias', language, text: item3Alias }
116116
} );
@@ -126,7 +126,7 @@ describe( 'Simple item search', () => {
126126
expect( response ).to.have.status( 200 );
127127
assert.deepEqual( response.body.results, [ {
128128
id: item1.id,
129-
label: { language: expectedFallbackLanguage, value: item1GermanLabel },
129+
'display-label': { language: expectedFallbackLanguage, value: item1GermanLabel },
130130
description: { language: expectedFallbackLanguage, value: item1GermanDescription },
131131
match: { type: 'label', language: expectedFallbackLanguage, text: item1GermanLabel }
132132
} ] );

repo/domains/search/tests/phpunit/Infrastructure/DataAccess/InLabelItemSearchEngineTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function searchResultsProvider(): Generator {
8484
)
8585
),
8686
];
87-
yield 'should not use alias as display label' => [
87+
yield 'alias as display label' => [
8888
[
8989
new TermSearchResult(
9090
new Term( 'en', 'spud' ),
@@ -97,7 +97,7 @@ public static function searchResultsProvider(): Generator {
9797
new ItemSearchResults(
9898
new ItemSearchResult(
9999
new ItemId( 'Q123' ),
100-
null,
100+
new Label( 'en', 'spud' ),
101101
new Description( 'en', 'root vegetable' ),
102102
new MatchedData( 'alias', 'en', 'spud' )
103103
)

repo/rest-api/src/openapi.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33636,7 +33636,7 @@
3363633636
"type": "string",
3363733637
"pattern": "^Q[1-9]\\d{0,9}$"
3363833638
},
33639-
"label": {
33639+
"display-label": {
3364033640
"type": [
3364133641
"object",
3364233642
"null"
@@ -33698,7 +33698,7 @@
3369833698
"additionalProperties": false,
3369933699
"required": [
3370033700
"id",
33701-
"label",
33701+
"display-label",
3370233702
"description",
3370333703
"match"
3370433704
]
@@ -33714,7 +33714,7 @@
3371433714
"results": [
3371533715
{
3371633716
"id": "Q123",
33717-
"label": {
33717+
"display-label": {
3371833718
"language": "en",
3371933719
"value": "potato"
3372033720
},
@@ -33730,7 +33730,7 @@
3373033730
},
3373133731
{
3373233732
"id": "Q234",
33733-
"label": {
33733+
"display-label": {
3373433734
"language": "en",
3373533735
"value": "potato"
3373633736
},
@@ -33846,7 +33846,7 @@
3384633846
"type": "string",
3384733847
"pattern": "^P[1-9]\\d{0,9}$"
3384833848
},
33849-
"label": {
33849+
"display-label": {
3385033850
"type": [
3385133851
"object",
3385233852
"null"
@@ -33908,7 +33908,7 @@
3390833908
"additionalProperties": false,
3390933909
"required": [
3391033910
"id",
33911-
"label",
33911+
"display-label",
3391233912
"description",
3391333913
"match"
3391433914
]
@@ -33924,7 +33924,7 @@
3392433924
"results": [
3392533925
{
3392633926
"id": "P123",
33927-
"label": {
33927+
"display-label": {
3392833928
"language": "en",
3392933929
"value": "taxon name"
3393033930
},
@@ -33940,7 +33940,7 @@
3394033940
},
3394133941
{
3394233942
"id": "P234",
33943-
"label": {
33943+
"display-label": {
3394433944
"language": "en",
3394533945
"value": "taxon rank"
3394633946
},
@@ -43035,7 +43035,7 @@
4303543035
"type": "string",
4303643036
"pattern": "^Q[1-9]\\d{0,9}$"
4303743037
},
43038-
"label": {
43038+
"display-label": {
4303943039
"type": [
4304043040
"object",
4304143041
"null"
@@ -43097,7 +43097,7 @@
4309743097
"additionalProperties": false,
4309843098
"required": [
4309943099
"id",
43100-
"label",
43100+
"display-label",
4310143101
"description",
4310243102
"match"
4310343103
]
@@ -43113,7 +43113,7 @@
4311343113
"results": [
4311443114
{
4311543115
"id": "Q123",
43116-
"label": {
43116+
"display-label": {
4311743117
"language": "en",
4311843118
"value": "potato"
4311943119
},
@@ -43129,7 +43129,7 @@
4312943129
},
4313043130
{
4313143131
"id": "Q234",
43132-
"label": {
43132+
"display-label": {
4313343133
"language": "en",
4313443134
"value": "potato"
4313543135
},
@@ -43210,7 +43210,7 @@
4321043210
"type": "string",
4321143211
"pattern": "^P[1-9]\\d{0,9}$"
4321243212
},
43213-
"label": {
43213+
"display-label": {
4321443214
"type": [
4321543215
"object",
4321643216
"null"
@@ -43272,7 +43272,7 @@
4327243272
"additionalProperties": false,
4327343273
"required": [
4327443274
"id",
43275-
"label",
43275+
"display-label",
4327643276
"description",
4327743277
"match"
4327843278
]
@@ -43288,7 +43288,7 @@
4328843288
"results": [
4328943289
{
4329043290
"id": "P123",
43291-
"label": {
43291+
"display-label": {
4329243292
"language": "en",
4329343293
"value": "taxon name"
4329443294
},
@@ -43304,7 +43304,7 @@
4330443304
},
4330543305
{
4330643306
"id": "P234",
43307-
"label": {
43307+
"display-label": {
4330843308
"language": "en",
4330943309
"value": "taxon rank"
4331043310
},

0 commit comments

Comments
 (0)