Skip to content

Commit ecac616

Browse files
meili-bors[bot]remigarciaRémi Garcia
authored
Merge #342
342: Fixed Engine::remove() when multiple entities are provided r=norkunas a=remigarcia # Pull Request ## Related issue Fixes #341 ## What does this PR do? - fixing the Engine::remove() method which was only removing the first object when multiple objects were provided ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Rémi Garcia <[email protected]> Co-authored-by: Rémi Garcia <[email protected]>
2 parents 835a737 + 5e1f5cd commit ecac616

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/Engine.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ public function remove($searchableEntities): array
9090

9191
$result = [];
9292
foreach ($data as $indexUid => $objects) {
93-
$result[$indexUid] = $this->client
94-
->index($indexUid)
95-
->deleteDocument(reset($objects));
93+
$result[$indexUid] = [];
94+
foreach ($objects as $object) {
95+
$result[$indexUid][] = $this->client
96+
->index($indexUid)
97+
->deleteDocument($object);
98+
}
9699
}
97100

98101
return $result;

tests/Integration/EngineTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,25 @@ public function testIndexingEmptyEntity(): void
4848
$this->assertInstanceOf(ApiException::class, $e);
4949
}
5050
}
51+
52+
public function testRemovingMultipleEntity(): void
53+
{
54+
$post1 = $this->createSearchablePost();
55+
$post2 = $this->createSearchablePost();
56+
57+
$result = $this->engine->remove([$post1, $post2]);
58+
59+
$this->assertArrayHasKey('sf_phpunit__posts', $result);
60+
$this->assertCount(2, $result['sf_phpunit__posts']);
61+
62+
$this->waitForAllTasks();
63+
64+
foreach ([$post1, $post2] as $post) {
65+
$searchResult = $this->engine->search('', $post->getIndexUid(), []);
66+
67+
$this->assertArrayHasKey('hits', $searchResult);
68+
$this->assertIsArray($searchResult['hits']);
69+
$this->assertEmpty($searchResult['hits']);
70+
}
71+
}
5172
}

0 commit comments

Comments
 (0)