Skip to content

Commit f940dd9

Browse files
bors[bot]meili-botcurquiza
authored
Merge #137
137: Changes related to the next MeiliSearch release (v0.25.0) r=curquiza a=meili-bot This PR gathers the changes related to the next MeiliSearch release (v0.25.0) so that this package is ready when the official release is out. ⚠️ This PR should NOT be merged until: - the next release of MeiliSearch (v0.25.0) is out. - the [`meilisearch-php`](https://github.com/meilisearch/meilisearch-php) dependency has been released to be compatible with MeiliSearch v0.25.0. Once the release is out, the upgrade of the `meilisearch-php` dependency might be committed to this branch. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Clémentine Urquizar - curqui <[email protected]>
2 parents 72bebdf + 2df2081 commit f940dd9

File tree

11 files changed

+87
-52
lines changed

11 files changed

+87
-52
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Also, see our [Documentation](https://docs.meilisearch.com/learn/tutorials/getti
4848

4949
## 🤖 Compatibility with Meilisearch
5050

51-
This package only guarantees the compatibility with the [version v0.24.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.24.0).
51+
This package only guarantees the compatibility with the [version v0.25.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.25.0).
5252

5353
## 💡 Learn More
5454

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"ext-json": "*",
2323
"doctrine/doctrine-bundle": "^2.4",
2424
"illuminate/collections": "^8.47",
25-
"meilisearch/meilisearch-php": "^0.20",
25+
"meilisearch/meilisearch-php": "^0.21.0",
2626
"symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
2727
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
2828
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"

src/Command/MeiliSearchCreateCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace MeiliSearch\Bundle\Command;
66

77
use MeiliSearch\Bundle\Exception\InvalidSettingName;
8-
use MeiliSearch\Bundle\Exception\UpdateException;
8+
use MeiliSearch\Bundle\Exception\TaskException;
99
use MeiliSearch\Bundle\Model\Aggregator;
1010
use MeiliSearch\Bundle\SearchService;
1111
use MeiliSearch\Client;
@@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6464

6565
$output->writeln('<info>Creating index '.$index['name'].' for '.$entityClassName.'</info>');
6666

67-
$indexInstance = $this->searchClient->getOrCreateIndex($index['name']);
67+
$indexInstance = $this->searchClient->index($index['name']);
6868

6969
if (isset($index['settings']) && is_array($index['settings'])) {
7070
foreach ($index['settings'] as $variable => $value) {
@@ -74,13 +74,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7474
throw new InvalidSettingName(sprintf('Invalid setting name: "%s"', $variable));
7575
}
7676

77-
$update = $indexInstance->{$method}($value);
77+
$task = $indexInstance->{$method}($value);
7878

79-
$indexInstance->waitForPendingUpdate($update['updateId']);
80-
$updateStatus = $indexInstance->getUpdateStatus($update['updateId']);
79+
$indexInstance->waitForTask($task['uid']);
80+
$task = $indexInstance->getTask($task['uid']);
8181

82-
if ('failed' === $updateStatus['status']) {
83-
throw new UpdateException($updateStatus['error']);
82+
if ('failed' === $task['status']) {
83+
throw new TaskException($task['error']);
8484
}
8585
}
8686
}

src/Command/MeiliSearchImportCommand.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Doctrine\Persistence\ManagerRegistry;
88
use MeiliSearch\Bundle\Exception\InvalidSettingName;
9-
use MeiliSearch\Bundle\Exception\UpdateException;
9+
use MeiliSearch\Bundle\Exception\TaskException;
1010
use MeiliSearch\Bundle\Model\Aggregator;
1111
use MeiliSearch\Bundle\SearchService;
1212
use MeiliSearch\Client;
@@ -116,22 +116,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
116116
if (isset($index['settings'])
117117
&& is_array($index['settings'])
118118
&& count($index['settings']) > 0) {
119-
$indexInstance = $this->searchClient->getOrCreateIndex($index['name']);
119+
$indexInstance = $this->searchClient->index($index['name']);
120120
foreach ($index['settings'] as $variable => $value) {
121121
$method = sprintf('update%s', ucfirst($variable));
122122
if (false === method_exists($indexInstance, $method)) {
123123
throw new InvalidSettingName(sprintf('Invalid setting name: "%s"', $variable));
124124
}
125125

126126
// Update
127-
$update = $indexInstance->{$method}($value);
127+
$task = $indexInstance->{$method}($value);
128128

129-
// Get Update status from updateID
130-
$indexInstance->waitForPendingUpdate($update['updateId'], $responseTimeout);
131-
$updateStatus = $indexInstance->getUpdateStatus($update['updateId']);
129+
// Get task information using uid
130+
$indexInstance->waitForTask($task['uid'], $responseTimeout);
131+
$task = $indexInstance->getTask($task['uid']);
132132

133-
if ('failed' === $updateStatus['status']) {
134-
throw new UpdateException($updateStatus['error']);
133+
if ('failed' === $task['status']) {
134+
throw new TaskException($task['error']);
135135
} else {
136136
$output->writeln('<info>Settings updated.</info>');
137137
}
@@ -164,15 +164,15 @@ private function formatIndexingResponse(array $batch, int $responseTimeout): arr
164164

165165
$indexInstance = $this->searchClient->index($indexName);
166166

167-
// Get Update status from updateID
168-
$indexInstance->waitForPendingUpdate($apiResponse['updateId'], $responseTimeout);
169-
$updateStatus = $indexInstance->getUpdateStatus($apiResponse['updateId']);
167+
// Get task information using uid
168+
$indexInstance->waitForTask($apiResponse['uid'], $responseTimeout);
169+
$task = $indexInstance->getTask($apiResponse['uid']);
170170

171-
if ('failed' === $updateStatus['status']) {
172-
throw new UpdateException($updateStatus['error']);
171+
if ('failed' === $task['status']) {
172+
throw new TaskException($task['error']);
173173
}
174174

175-
$formattedResponse[$indexName] += $updateStatus['type']['number'];
175+
$formattedResponse[$indexName] += $task['details']['indexedDocuments'];
176176
}
177177
}
178178

src/Engine.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function index($searchableEntities): array
5454
$result = [];
5555
foreach ($data as $indexUid => $objects) {
5656
$result[$indexUid] = $this->client
57-
->getOrCreateIndex($indexUid, ['primaryKey' => 'objectID'])
58-
->addDocuments($objects);
57+
->index($indexUid)
58+
->addDocuments($objects, 'objectID');
5959
}
6060

6161
return $result;
@@ -104,19 +104,20 @@ public function remove($searchableEntities): array
104104
/**
105105
* Clear the records of an index.
106106
* This method enables you to delete an index’s contents (records).
107+
* Will fail if the index does not exists.
107108
*
108109
* @throws ApiException
109110
*/
110111
public function clear(string $indexUid): array
111112
{
112-
$index = $this->client->getOrCreateIndex($indexUid);
113-
$return = $index->deleteAllDocuments();
113+
$index = $this->client->index($indexUid);
114+
$task = $index->deleteAllDocuments();
114115

115-
return $index->getUpdateStatus($return['updateId']);
116+
return $task;
116117
}
117118

118119
/**
119-
* Delete an index and it's content.
120+
* Delete an index and its content.
120121
*/
121122
public function delete(string $indexUid): ?array
122123
{

src/Exception/UpdateException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace MeiliSearch\Bundle\Exception;
66

77
/**
8-
* Class UpdateException.
8+
* Class TaskException.
99
*/
10-
final class UpdateException extends \LogicException
10+
final class TaskException extends \LogicException
1111
{
1212
}

src/SearchableEntity.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ public function getIndexUid(): string
6161
*/
6262
public function getSearchableArray(): array
6363
{
64-
/** @var \Doctrine\ORM\Mapping\ClassMetadataInfo&\Doctrine\Persistence\Mapping\ClassMetadata $metadata */
65-
$metadata = $this->entityMetadata;
66-
6764
$context = [
68-
'fieldsMapping' => $metadata->fieldMappings,
65+
/* @phpstan-ignore-next-line */
66+
'fieldsMapping' => $this->entityMetadata->fieldMappings,
6967
];
7068

7169
if ($this->useSerializerGroups) {

tests/Integration/CommandsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function setUp(): void
3232
parent::setUp();
3333

3434
$this->client = $this->get('search.client');
35-
$this->index = $this->client->getOrCreateIndex($this->getPrefix().self::$indexName);
35+
$this->index = $this->client->index($this->getPrefix().self::$indexName);
3636
$this->application = new Application(self::createKernel());
3737
}
3838

@@ -221,7 +221,7 @@ public function testImportDifferentEntitiesIntoSameIndex(): void
221221
$this->assertStringContainsString('Done!', $output);
222222

223223
/** @var SearchResult $searchResult */
224-
$searchResult = $this->client->getOrCreateIndex($this->getPrefix().'tags')->search('Test');
224+
$searchResult = $this->client->index($this->getPrefix().'tags')->search('Test');
225225
$this->assertCount(8, $searchResult->getHits());
226226
$this->assertSame(8, $searchResult->getHitsCount());
227227
}

tests/Integration/EventListener/DoctrineEventSubscriberTest.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,24 @@
99
use MeiliSearch\Bundle\Test\BaseKernelTestCase;
1010
use MeiliSearch\Bundle\Test\Entity\Page;
1111
use MeiliSearch\Bundle\Test\Entity\Post;
12+
use MeiliSearch\Client;
1213

1314
class DoctrineEventSubscriberTest extends BaseKernelTestCase
1415
{
16+
protected Client $client;
17+
18+
/**
19+
* @throws \Exception
20+
*/
21+
public function setUp(): void
22+
{
23+
parent::setUp();
24+
25+
$this->client = $this->get('search.client');
26+
}
27+
1528
/**
16-
* This tests creates two posts in the database, but only one is triggered via an event to MS.
29+
* This tests creates two posts in the database, but only one is triggered via an event to Meilisearch.
1730
*/
1831
public function testPostPersist(): void
1932
{
@@ -25,6 +38,8 @@ public function testPostPersist(): void
2538
$subscriber = new DoctrineEventSubscriber($this->searchService, []);
2639
$subscriber->postPersist($eventArgs);
2740

41+
$this->waitForAllTasks();
42+
2843
$result = $this->searchService->search($this->entityManager, Post::class, $post->getTitle());
2944

3045
$this->assertCount(1, $result);
@@ -40,7 +55,8 @@ public function testPostPersistWithObjectId(): void
4055

4156
$subscriber = new DoctrineEventSubscriber($this->searchService, []);
4257
$subscriber->postPersist($eventArgs);
43-
sleep(1);
58+
59+
$this->waitForAllTasks();
4460

4561
$result = $this->searchService->search($this->entityManager, Page::class, $page->getTitle());
4662

@@ -49,7 +65,7 @@ public function testPostPersistWithObjectId(): void
4965
}
5066

5167
/**
52-
* This tests creates two posts in the database, but only one is triggered via an event to MS.
68+
* This tests creates two posts in the database, but only one is triggered via an event to Meilisearch.
5369
*/
5470
public function testPostUpdate(): void
5571
{
@@ -61,6 +77,8 @@ public function testPostUpdate(): void
6177
$subscriber = new DoctrineEventSubscriber($this->searchService, []);
6278
$subscriber->postUpdate($eventArgs);
6379

80+
$this->waitForAllTasks();
81+
6482
$result = $this->searchService->search($this->entityManager, Post::class, $post->getTitle());
6583

6684
$this->assertCount(1, $result);
@@ -76,7 +94,8 @@ public function testPostUpdateWithObjectId(): void
7694

7795
$subscriber = new DoctrineEventSubscriber($this->searchService, []);
7896
$subscriber->postUpdate($eventArgs);
79-
sleep(1);
97+
98+
$this->waitForAllTasks();
8099

81100
$result = $this->searchService->search($this->entityManager, Page::class, $page->getTitle());
82101

@@ -85,7 +104,7 @@ public function testPostUpdateWithObjectId(): void
85104
}
86105

87106
/**
88-
* This tests creates posts in the database, send it to MS via a trigger. Afterwards Doctrines 'preRemove' event
107+
* This tests creates posts in the database, send it to Meilisearch via a trigger. Afterwards Doctrines 'preRemove' event
89108
* is going to remove that entity from MS.
90109
*/
91110
public function testPreRemove(): void
@@ -97,18 +116,16 @@ public function testPreRemove(): void
97116
$subscriber = new DoctrineEventSubscriber($this->searchService, []);
98117
$subscriber->postPersist($eventArgs);
99118

119+
$this->waitForAllTasks();
120+
100121
$result = $this->searchService->search($this->entityManager, Post::class, $post->getTitle());
101122

102123
$this->assertCount(1, $result);
103124
$this->assertSame(1, $result[0]->getId());
104125

105126
$subscriber->preRemove($eventArgs);
106127

107-
/*
108-
* As the deletion of a document is an asyncronous transaction, we need to wait some seconds
109-
* till this is executed. This was introduced as with Github actions there was no other option.
110-
*/
111-
sleep(2);
128+
$this->waitForAllTasks();
112129

113130
$result = $this->searchService->search($this->entityManager, Post::class, $post->getTitle());
114131

@@ -123,18 +140,29 @@ public function testPreRemoveWithObjectId(): void
123140

124141
$subscriber = new DoctrineEventSubscriber($this->searchService, []);
125142
$subscriber->postPersist($eventArgs);
126-
sleep(1);
143+
144+
$this->waitForAllTasks();
127145

128146
$result = $this->searchService->search($this->entityManager, Page::class, $page->getTitle());
129147

130148
$this->assertCount(1, $result);
131149
$this->assertSame((string) $page->getId(), (string) $result[0]->getId());
132150

133151
$subscriber->preRemove($eventArgs);
134-
sleep(1);
152+
153+
$this->waitForAllTasks();
135154

136155
$result = $this->searchService->search($this->entityManager, Page::class, $page->getTitle());
137156

138157
$this->assertCount(0, $result);
139158
}
159+
160+
/**
161+
* Waits for all the tasks to be finished by checking the topest one (so the newest one).
162+
*/
163+
private function waitForAllTasks(): void
164+
{
165+
$firstTask = $this->client->getTasks()['results'][0];
166+
$this->client->waitForTask($firstTask['uid']);
167+
}
140168
}

tests/Integration/SearchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function setUp(): void
4040

4141
$this->client = $this->get('search.client');
4242
$this->objectManager = $this->get('doctrine')->getManager();
43-
$this->index = $this->client->getOrCreateIndex($this->getPrefix().self::$indexName);
43+
$this->index = $this->client->index($this->getPrefix().self::$indexName);
4444
$this->application = new Application(self::createKernel());
4545
}
4646

tests/Integration/SettingsTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ public function setUp(): void
4343
public function testGetDefaultSettings(): void
4444
{
4545
$primaryKey = 'ObjectID';
46-
$settingA = $this->client->getOrCreateIndex($this->getPrefix().'indexA')->getSettings();
47-
$settingB = $this->client->getOrCreateIndex($this->getPrefix().'indexB', ['primaryKey' => $primaryKey])->getSettings();
46+
$indexAName = $this->getPrefix().'indexA';
47+
$indexBName = $this->getPrefix().'indexB';
48+
$this->client->createIndex($indexAName);
49+
$this->client->createIndex($indexBName, ['primaryKey' => $primaryKey]);
50+
51+
$firstTask = $this->client->getTasks()['results'][0];
52+
$this->client->waitForTask($firstTask['uid']);
53+
54+
$settingA = $this->client->index($indexAName)->getSettings();
55+
$settingB = $this->client->index($indexBName)->getSettings();
4856

4957
$this->assertEquals(self::DEFAULT_RANKING_RULES, $settingA['rankingRules']);
5058
$this->assertNull($settingA['distinctAttribute']);

0 commit comments

Comments
 (0)