Skip to content

Commit

Permalink
Merge pull request #422 from meilisearch/bump-meilisearch-v0.30.0-add…
Browse files Browse the repository at this point in the history
…-swap-indexes

Add `swapIndexes` method
  • Loading branch information
brunoocasali authored Nov 24, 2022
2 parents 8229a6b + cbf4c16 commit 20c35c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Delegates/HandlesSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ public function generateTenantToken(string $apiKeyUid, $searchRules, ?array $opt
{
return $this->tenantToken->generateTenantToken($apiKeyUid, $searchRules, $options);
}

public function swapIndexes(array $indexes)
{
$options = array_map(function ($data) { return ['indexes' => $data]; }, $indexes);

return $this->index->swapIndexes($options);
}
}
8 changes: 8 additions & 0 deletions src/Endpoints/Indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ public function delete(): array
return $this->http->delete(self::PATH.'/'.$this->uid) ?? [];
}

/**
* @param array<array{indexes: mixed}> $indexes
*/
public function swapIndexes(array $indexes): array
{
return $this->http->post('/swap-indexes', $indexes);
}

// Tasks

public function getTask($uid): array
Expand Down
8 changes: 8 additions & 0 deletions tests/Endpoints/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ public function testDeleteIndexes(): void
$this->assertArrayHasKey('enqueuedAt', $res);
}

public function testSwapIndexes(): void
{
$promise = $this->client->swapIndexes([['indexA', 'indexB'], ['indexC', 'indexD']]);
$response = $this->client->waitForTask($promise['taskUid']);

$this->assertSame($response['details']['swaps'], [['indexes' => ['indexA', 'indexB']], ['indexes' => ['indexC', 'indexD']]]);
}

public function testParseDate(): void
{
$date = '2021-01-01T01:23:45.123456Z';
Expand Down

0 comments on commit 20c35c8

Please sign in to comment.