diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index f30752df..695e1154 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(); diff --git a/src/Endpoints/Delegates/HandlesSettings.php b/src/Endpoints/Delegates/HandlesSettings.php index 65795d27..8d43f2f1 100644 --- a/src/Endpoints/Delegates/HandlesSettings.php +++ b/src/Endpoints/Delegates/HandlesSettings.php @@ -341,4 +341,24 @@ 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'); + } + + 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..1d690572 --- /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->assertSame('byWord', $default); + } + + public function testUpdateProximityPrecision(): void + { + $promise = $this->index->updateProximityPrecision('byAttribute'); + $this->assertIsValidPromise($promise); + $this->index->waitForTask($promise['taskUid']); + + $this->assertSame('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->assertSame('byWord', $this->index->getProximityPrecision()); + } +}