Skip to content

Commit c5b81f9

Browse files
Striftnorkunasthijskuilman
authored
chore: backport federated search fix (#789)
* Update repository config for v2 (#787) * Update CI workflows * Update contributors * Update empty string comparison * lint * Cast federation payload explicilty to an object (#757) * Cast federation payload explicilty to an object * Add unit test for multisearch federation array to object casting --------- Co-authored-by: Thijs Kuilman <thijs.kuilman@gmail.com> Co-authored-by: Laurent Cazanove <lau.cazanove@gmail.com> --------- Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com> Co-authored-by: Thijs Kuilman <thijs.kuilman@gmail.com>
1 parent 04f7e54 commit c5b81f9

File tree

8 files changed

+48
-6
lines changed

8 files changed

+48
-6
lines changed

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- v1.x
78

89
jobs:
910
update_release_draft:

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- staging
1010
- main
1111
- feature/**
12+
- v1.x
1213

1314
jobs:
1415
yaml-lint:

composer.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@
1313
"license": "MIT",
1414
"authors": [
1515
{
16-
"name": "Clementine",
16+
"name": "Clémentine Urquizar",
1717
"email": "clementine@meilisearch.com"
18+
},
19+
{
20+
"name": "Bruno Casali",
21+
"email": "bruno@meilisearch.com"
22+
},
23+
{
24+
"name": "Laurent Cazanove",
25+
"email": "lau.cazanove@gmail.com"
26+
},
27+
{
28+
"name": "Tomas Norkūnas",
29+
"email": "norkunas.tom@gmail.com"
1830
}
1931
],
2032
"minimum-stability": "stable",
@@ -58,7 +70,9 @@
5870
"./vendor/bin/php-cs-fixer fix --verbose --config=.php-cs-fixer.dist.php --using-cache=no --diff"
5971
],
6072
"phpstan": "./vendor/bin/phpstan",
61-
"test": ["sh scripts/tests.sh"]
73+
"test": [
74+
"sh scripts/tests.sh"
75+
]
6276
},
6377
"config": {
6478
"allow-plugins": {

src/Endpoints/Delegates/HandlesMultiSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function multiSearch(array $queries = [], ?MultiSearchFederation $federat
2525

2626
$payload = ['queries' => $body];
2727
if (null !== $federation) {
28-
$payload['federation'] = $federation->toArray();
28+
$payload['federation'] = (object) $federation->toArray();
2929
}
3030

3131
return $this->http->post('/multi-search', $payload);

src/Exceptions/ApiException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __toString()
3333
{
3434
$base = 'Meilisearch ApiException: Http Status: '.$this->httpStatus;
3535

36-
if (!\is_null($this->message)) {
36+
if ('' !== $this->message) {
3737
$base .= ' - Message: '.$this->message;
3838
}
3939

src/Exceptions/InvalidResponseBodyException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __toString()
2525
{
2626
$base = 'Meilisearch InvalidResponseBodyException: Http Status: '.$this->httpStatus;
2727

28-
if ($this->message) {
28+
if ('' !== $this->message) {
2929
$base .= ' - Message: '.$this->message;
3030
}
3131

src/Exceptions/TimeOutException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(?string $message = null, ?int $code = null, ?\Throwa
2020
public function __toString()
2121
{
2222
$base = 'Meilisearch TimeOutException: Code: '.$this->code;
23-
if ($this->message) {
23+
if ('' !== $this->message) {
2424
return $base.' - Message: '.$this->message;
2525
} else {
2626
return $base;

tests/Endpoints/MultiSearchTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
namespace Tests\Endpoints;
66

7+
use Meilisearch\Client;
78
use Meilisearch\Contracts\FederationOptions;
89
use Meilisearch\Contracts\MultiSearchFederation;
910
use Meilisearch\Contracts\SearchQuery;
1011
use Meilisearch\Endpoints\Indexes;
12+
use Symfony\Component\HttpClient\MockHttpClient;
13+
use Symfony\Component\HttpClient\Psr18Client;
14+
use Symfony\Component\HttpClient\Response\MockResponse;
1115
use Tests\TestCase;
1216

1317
final class MultiSearchTest extends TestCase
@@ -159,4 +163,26 @@ public function testMultiSearchWithDistinctAttribute(): void
159163
self::assertCount(1, $response['results'][1]['hits']);
160164
self::assertSame('fantasy', $response['results'][1]['hits'][0]['genre']);
161165
}
166+
167+
public function testMultiSearchFederationCastingToObject(): void
168+
{
169+
$httpClient = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse {
170+
self::assertSame('POST', $method);
171+
self::assertSame('http://meilisearch/multi-search', $url);
172+
self::assertSame('{"queries":[{"indexUid":"first"},{"indexUid":"second"}],"federation":{}}', $options['body']);
173+
174+
return new MockResponse(
175+
json_encode(['results' => []], \JSON_THROW_ON_ERROR),
176+
['response_headers' => ['content-type' => 'application/json']],
177+
);
178+
});
179+
180+
$client = new Client('http://meilisearch', 'apikey', new Psr18Client($httpClient));
181+
$client->multiSearch([
182+
(new SearchQuery())->setIndexUid('first'),
183+
(new SearchQuery())->setIndexUid('second'),
184+
],
185+
new MultiSearchFederation()
186+
);
187+
}
162188
}

0 commit comments

Comments
 (0)