Skip to content

Commit dd3ad9e

Browse files
committed
Search: Leave out "language":"qid" from matched results
Bug: T391663 Change-Id: Ic9a262e249bbc71decc47c73d67db6cf386cb026
1 parent 1095250 commit dd3ad9e

File tree

9 files changed

+60
-12
lines changed

9 files changed

+60
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"text": { "type": "string" }
2626
},
2727
"additionalProperties": false,
28-
"required": [ "type", "language", "text" ]
28+
"required": [ "type", "text" ]
2929
},
3030
"SearchItemResult": {
3131
"type": "object",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ private function convertResult( string $resultClass ): callable {
7070
: null,
7171
new MatchedData(
7272
$result->getMatchedTermType(),
73-
$result->getMatchedTerm()->getLanguageCode(),
73+
$result->getMatchedTerm()->getLanguageCode() === 'qid' ?
74+
null :
75+
$result->getMatchedTerm()->getLanguageCode(),
7476
$result->getMatchedTerm()->getText()
7577
)
7678
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ private function formatResults( ItemSearchResults $results ): array {
9393
'language' => $result->getDescription()->getLanguageCode(),
9494
'value' => $result->getDescription()->getText(),
9595
] : null,
96-
'match' => [
96+
'match' => array_filter( [
9797
'type' => $result->getMatchedData()->getType(),
9898
'language' => $result->getMatchedData()->getLanguageCode(),
9999
'text' => $result->getMatchedData()->getText(),
100-
],
100+
] ),
101101
],
102102
iterator_to_array( $results )
103103
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ private function formatResults( PropertySearchResults $results ): array {
9393
'language' => $result->getDescription()->getLanguageCode(),
9494
'value' => $result->getDescription()->getText(),
9595
] : null,
96-
'match' => [
96+
'match' => array_filter( [
9797
'type' => $result->getMatchedData()->getType(),
9898
'language' => $result->getMatchedData()->getLanguageCode(),
9999
'text' => $result->getMatchedData()->getText(),
100-
],
100+
] ),
101101
],
102102
iterator_to_array( $results )
103103
);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ describe( 'Simple item search', () => {
139139
} ] );
140140
} );
141141

142+
it( 'finds an item by Q-ID', async () => {
143+
const response = await newSearchRequest( 'en', item1.id )
144+
.assertValidRequest()
145+
.makeRequest();
146+
147+
expect( response ).to.have.status( 200 );
148+
assert.deepEqual( response.body.results, [ {
149+
id: item1.id,
150+
'display-label': { language: 'en', value: item1Label },
151+
description: { language: 'en', value: item1Description },
152+
match: { type: 'entityId', text: item1.id }
153+
} ] );
154+
} );
155+
142156
it( 'finds nothing if no items match', async () => {
143157
const response = await newSearchRequest( 'en', utils.uniq( 40 ) )
144158
.assertValidRequest()

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ describe( 'Simple property search', () => {
126126
} ] );
127127
} );
128128

129+
it( 'finds a property by P-ID', async () => {
130+
const response = await newSearchRequest( 'en', property1.id )
131+
.assertValidRequest()
132+
.makeRequest();
133+
134+
expect( response ).to.have.status( 200 );
135+
assert.deepEqual( response.body.results, [ {
136+
id: property1.id,
137+
'display-label': { language: 'en', value: property1.labels.en },
138+
description: { language: 'en', value: property1.descriptions.en },
139+
match: { type: 'entityId', text: property1.id }
140+
} ] );
141+
} );
142+
129143
it( 'finds nothing if no properties match', async () => {
130144
const response = await newSearchRequest( 'en', utils.uniq( 40 ) )
131145
.assertValidRequest()

repo/domains/search/tests/mocha/openapi-validation/SimpleItemSearchTest.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ function newSearchRequest( language, searchTerm ) {
2020

2121
describe( 'Simple item search', () => {
2222
const itemEnLabel = utils.title( 'english-label' );
23+
let item;
2324

2425
before( async () => {
25-
await createItem( { labels: { en: itemEnLabel } } );
26+
item = await createItem( { labels: { en: itemEnLabel } } );
2627

2728
await wiki.runAllJobs();
2829
await new Promise( ( resolve ) => {
@@ -50,6 +51,16 @@ describe( 'Simple item search', () => {
5051
expect( response ).to.satisfyApiSchema;
5152
} );
5253

54+
it( '200 - search response by ID (without language match)', async () => {
55+
const response = await newSearchRequest( 'en', item.id )
56+
.assertValidRequest()
57+
.makeRequest();
58+
59+
expect( response ).to.have.status( 200 );
60+
assert.lengthOf( response.body.results, 1 );
61+
expect( response ).to.satisfyApiSchema;
62+
} );
63+
5364
it( '400 - invalid language code', async () => {
5465
const response = await newSearchRequest( 'not_a_valid_language', utils.uniq( 40 ) )
5566
.assertInvalidRequest()

repo/domains/search/tests/mocha/openapi-validation/SimplePropertySearchTest.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ function newSearchRequest( language, searchTerm ) {
2020

2121
describe( 'Simple property search', () => {
2222
const propertyEnLabel = utils.title( 'english-label' );
23+
let property;
2324

2425
before( async () => {
25-
await createProperty( {
26+
property = await createProperty( {
2627
data_type: 'string',
2728
labels: { en: propertyEnLabel }
2829
} );
@@ -53,6 +54,16 @@ describe( 'Simple property search', () => {
5354
expect( response ).to.satisfyApiSchema;
5455
} );
5556

57+
it( '200 - search response by ID (without language match)', async () => {
58+
const response = await newSearchRequest( 'en', property.id )
59+
.assertValidRequest()
60+
.makeRequest();
61+
62+
expect( response ).to.have.status( 200 );
63+
assert.lengthOf( response.body.results, 1 );
64+
expect( response ).to.satisfyApiSchema;
65+
} );
66+
5667
it( '400 - invalid language code', async () => {
5768
const response = await newSearchRequest( 'not_a_valid_language', utils.uniq( 40 ) )
5869
.assertInvalidRequest()

repo/rest-api/src/openapi.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33715,7 +33715,6 @@
3371533715
"additionalProperties": false,
3371633716
"required": [
3371733717
"type",
33718-
"language",
3371933718
"text"
3372033719
]
3372133720
}
@@ -33950,7 +33949,6 @@
3395033949
"additionalProperties": false,
3395133950
"required": [
3395233951
"type",
33953-
"language",
3395433952
"text"
3395533953
]
3395633954
}
@@ -43164,7 +43162,6 @@
4316443162
"additionalProperties": false,
4316543163
"required": [
4316643164
"type",
43167-
"language",
4316843165
"text"
4316943166
]
4317043167
}
@@ -43339,7 +43336,6 @@
4333943336
"additionalProperties": false,
4334043337
"required": [
4334143338
"type",
43342-
"language",
4334343339
"text"
4334443340
]
4334543341
}

0 commit comments

Comments
 (0)