From 0e48bfd61adfcb85f9fd15366c4b281e1700252d Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Wed, 10 Jan 2024 15:24:39 -0300 Subject: [PATCH 1/4] Add proximityPrecision settings management methods --- src/Endpoints/Delegates/HandlesSettings.php | 23 ++++++++++ tests/Settings/ProximityPrecisionTest.php | 49 +++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/Settings/ProximityPrecisionTest.php diff --git a/src/Endpoints/Delegates/HandlesSettings.php b/src/Endpoints/Delegates/HandlesSettings.php index 65795d27..b817cac6 100644 --- a/src/Endpoints/Delegates/HandlesSettings.php +++ b/src/Endpoints/Delegates/HandlesSettings.php @@ -341,4 +341,27 @@ public function resetNonSeparatorTokens(): array { return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/non-separator-tokens'); } + + // Settings - proximityPrecision + + /** + * @return non-empty-string + */ + public function getProximityPrecision(): string + { + return $this->http->get(self::PATH.'/'.$this->uid.'/settings/proximity-precision'); + } + + /** + * @param non-empty-string $type + */ + public function updateProximityPrecision(string $type): array + { + return $this->http->put(self::PATH.'/'.$this->uid.'/settings/proximity-precision', $type); + } + + public function resetProximityPrecision(): array + { + return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/proximity-precision'); + } } diff --git a/tests/Settings/ProximityPrecisionTest.php b/tests/Settings/ProximityPrecisionTest.php new file mode 100644 index 00000000..f018de13 --- /dev/null +++ b/tests/Settings/ProximityPrecisionTest.php @@ -0,0 +1,49 @@ +index = $this->createEmptyIndex($this->safeIndexName()); + } + + public function testGetDefaultProximityPrecision(): void + { + $default = $this->index->getProximityPrecision(); + + $this->assertEquals($default, "byWord"); + } + + public function testUpdateProximityPrecision(): void + { + $promise = $this->index->updateProximityPrecision("byAttribute"); + $this->assertIsValidPromise($promise); + $this->index->waitForTask($promise['taskUid']); + + $this->assertEquals("byAttribute", $this->index->getProximityPrecision()); + } + + public function testResetProximityPrecision(): void + { + $promise = $this->index->updateProximityPrecision("byAttribute"); + $this->assertIsValidPromise($promise); + $this->index->waitForTask($promise['taskUid']); + + $promise = $this->index->resetProximityPrecision(); + + $this->assertIsValidPromise($promise); + $this->index->waitForTask($promise['taskUid']); + + $this->assertEquals($this->index->getProximityPrecision(), "byWord"); + } +} From 3b940dd3955aafb2cd6a587f2c79ff507e954fd7 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Wed, 10 Jan 2024 15:25:06 -0300 Subject: [PATCH 2/4] Update code-samples --- .code-samples.meilisearch.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index f30752df..a895799b 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -697,3 +697,9 @@ update_non_separator_tokens_1: |- $client->index('articles')->updateNonSeparatorTokens(['@', '#']); reset_non_separator_tokens_1: |- $client->index('articles')->resetNonSeparatorTokens(); +get_proximity_precision_settings_1: |- + $client->index('books')->getProximityPrecision(); +update_proximity_precision_settings_1: |- + $client->index('books')->updateProximityPrecision("byAttribute"); +reset_proximity_precision_settings_1: |- + $client->index('books')->resetProximityPrecision(); From 216bafebd41817ef753a76dcffab250f3efccbf0 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Wed, 10 Jan 2024 15:27:06 -0300 Subject: [PATCH 3/4] Improve typing system --- .code-samples.meilisearch.yaml | 2 +- src/Endpoints/Delegates/HandlesSettings.php | 7 +++++-- tests/Settings/ProximityPrecisionTest.php | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index a895799b..695e1154 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -700,6 +700,6 @@ reset_non_separator_tokens_1: |- get_proximity_precision_settings_1: |- $client->index('books')->getProximityPrecision(); update_proximity_precision_settings_1: |- - $client->index('books')->updateProximityPrecision("byAttribute"); + $client->index('books')->updateProximityPrecision('byAttribute'); reset_proximity_precision_settings_1: |- $client->index('books')->resetProximityPrecision(); diff --git a/src/Endpoints/Delegates/HandlesSettings.php b/src/Endpoints/Delegates/HandlesSettings.php index b817cac6..081f6571 100644 --- a/src/Endpoints/Delegates/HandlesSettings.php +++ b/src/Endpoints/Delegates/HandlesSettings.php @@ -355,12 +355,15 @@ public function getProximityPrecision(): string /** * @param non-empty-string $type */ - public function updateProximityPrecision(string $type): array + public function updateProximityPrecision(string $type): string { return $this->http->put(self::PATH.'/'.$this->uid.'/settings/proximity-precision', $type); } - public function resetProximityPrecision(): array + /** + * @return non-empty-string + */ + public function resetProximityPrecision(): string { return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/proximity-precision'); } diff --git a/tests/Settings/ProximityPrecisionTest.php b/tests/Settings/ProximityPrecisionTest.php index f018de13..1d690572 100644 --- a/tests/Settings/ProximityPrecisionTest.php +++ b/tests/Settings/ProximityPrecisionTest.php @@ -21,21 +21,21 @@ public function testGetDefaultProximityPrecision(): void { $default = $this->index->getProximityPrecision(); - $this->assertEquals($default, "byWord"); + $this->assertSame('byWord', $default); } public function testUpdateProximityPrecision(): void { - $promise = $this->index->updateProximityPrecision("byAttribute"); + $promise = $this->index->updateProximityPrecision('byAttribute'); $this->assertIsValidPromise($promise); $this->index->waitForTask($promise['taskUid']); - $this->assertEquals("byAttribute", $this->index->getProximityPrecision()); + $this->assertSame('byAttribute', $this->index->getProximityPrecision()); } public function testResetProximityPrecision(): void { - $promise = $this->index->updateProximityPrecision("byAttribute"); + $promise = $this->index->updateProximityPrecision('byAttribute'); $this->assertIsValidPromise($promise); $this->index->waitForTask($promise['taskUid']); @@ -44,6 +44,6 @@ public function testResetProximityPrecision(): void $this->assertIsValidPromise($promise); $this->index->waitForTask($promise['taskUid']); - $this->assertEquals($this->index->getProximityPrecision(), "byWord"); + $this->assertSame('byWord', $this->index->getProximityPrecision()); } } From 7f53abefdfb0b36762fa3bcfa11d55234b02015f Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Sun, 14 Jan 2024 22:07:21 -0300 Subject: [PATCH 4/4] Fix phpstan errors --- src/Endpoints/Delegates/HandlesSettings.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Endpoints/Delegates/HandlesSettings.php b/src/Endpoints/Delegates/HandlesSettings.php index 081f6571..8d43f2f1 100644 --- a/src/Endpoints/Delegates/HandlesSettings.php +++ b/src/Endpoints/Delegates/HandlesSettings.php @@ -352,18 +352,12 @@ public function getProximityPrecision(): string return $this->http->get(self::PATH.'/'.$this->uid.'/settings/proximity-precision'); } - /** - * @param non-empty-string $type - */ - public function updateProximityPrecision(string $type): string + public function updateProximityPrecision(string $type): array { return $this->http->put(self::PATH.'/'.$this->uid.'/settings/proximity-precision', $type); } - /** - * @return non-empty-string - */ - public function resetProximityPrecision(): string + public function resetProximityPrecision(): array { return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/proximity-precision'); }