diff --git a/src/Endpoints/Delegates/HandlesSettings.php b/src/Endpoints/Delegates/HandlesSettings.php index a4dec7ef..88afe17c 100644 --- a/src/Endpoints/Delegates/HandlesSettings.php +++ b/src/Endpoints/Delegates/HandlesSettings.php @@ -421,4 +421,60 @@ public function resetEmbedders(): array { return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/embedders'); } + + // Settings - Facet Search + + /** + * @since Meilisearch v1.12.0 + */ + public function getFacetSearch(): bool + { + return $this->http->get(self::PATH.'/'.$this->uid.'/settings/facet-search'); + } + + /** + * @since Meilisearch v1.12.0 + */ + public function updateFacetSearch(bool $facetSearch): array + { + return $this->http->put(self::PATH.'/'.$this->uid.'/settings/facet-search', $facetSearch); + } + + /** + * @since Meilisearch v1.12.0 + */ + public function resetFacetSearch(): array + { + return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/facet-search'); + } + + // Settings - Prefix Search + + /** + * @return 'indexingTime'|'disabled' + * + * @since Meilisearch v1.12.0 + */ + public function getPrefixSearch(): string + { + return $this->http->get(self::PATH.'/'.$this->uid.'/settings/prefix-search'); + } + + /** + * @param 'indexingTime'|'disabled' $prefixSearch + * + * @since Meilisearch v1.12.0 + */ + public function updatePrefixSearch(string $prefixSearch): array + { + return $this->http->put(self::PATH.'/'.$this->uid.'/settings/prefix-search', $prefixSearch); + } + + /** + * @since Meilisearch v1.12.0 + */ + public function resetPrefixSearch(): array + { + return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/prefix-search'); + } } diff --git a/tests/Settings/FacetSearchTest.php b/tests/Settings/FacetSearchTest.php new file mode 100644 index 00000000..ae05199b --- /dev/null +++ b/tests/Settings/FacetSearchTest.php @@ -0,0 +1,49 @@ +createEmptyIndex($this->safeIndexName()); + + $facetSearch = $index->getFacetSearch(); + + self::assertTrue($facetSearch); + } + + public function testUpdateFacetSearch(): void + { + $index = $this->createEmptyIndex($this->safeIndexName()); + + $promise = $index->updateFacetSearch(false); + + $this->assertIsValidPromise($promise); + $index->waitForTask($promise['taskUid']); + + $facetSearch = $index->getFacetSearch(); + self::assertFalse($facetSearch); + } + + public function testResetFacetSearch(): void + { + $index = $this->createEmptyIndex($this->safeIndexName()); + + $promise = $index->updateFacetSearch(false); + $index->waitForTask($promise['taskUid']); + + $promise = $index->resetFacetSearch(); + + $this->assertIsValidPromise($promise); + + $index->waitForTask($promise['taskUid']); + + $facetSearch = $index->getFacetSearch(); + self::assertTrue($facetSearch); + } +} diff --git a/tests/Settings/PrefixSearchTest.php b/tests/Settings/PrefixSearchTest.php new file mode 100644 index 00000000..2e93bd93 --- /dev/null +++ b/tests/Settings/PrefixSearchTest.php @@ -0,0 +1,49 @@ +createEmptyIndex($this->safeIndexName()); + + $prefixSearch = $index->getPrefixSearch(); + + self::assertSame('indexingTime', $prefixSearch); + } + + public function testUpdatePrefixSearch(): void + { + $index = $this->createEmptyIndex($this->safeIndexName()); + + $promise = $index->updatePrefixSearch('disabled'); + + $this->assertIsValidPromise($promise); + $index->waitForTask($promise['taskUid']); + + $prefixSearch = $index->getPrefixSearch(); + self::assertSame('disabled', $prefixSearch); + } + + public function testResetPrefixSearch(): void + { + $index = $this->createEmptyIndex($this->safeIndexName()); + + $promise = $index->updatePrefixSearch('disabled'); + $index->waitForTask($promise['taskUid']); + + $promise = $index->resetPrefixSearch(); + + $this->assertIsValidPromise($promise); + + $index->waitForTask($promise['taskUid']); + + $prefixSearch = $index->getPrefixSearch(); + self::assertSame('indexingTime', $prefixSearch); + } +} diff --git a/tests/Settings/SettingsTest.php b/tests/Settings/SettingsTest.php index 95c5bf6f..36b52179 100644 --- a/tests/Settings/SettingsTest.php +++ b/tests/Settings/SettingsTest.php @@ -29,6 +29,8 @@ final class SettingsTest extends TestCase public const DEFAULT_SEARCHABLE_ATTRIBUTES = ['*']; public const DEFAULT_DISPLAYED_ATTRIBUTES = ['*']; + public const DEFAULT_FACET_SEARCH = true; + public const DEFAULT_PREFIX_SEARCH = 'indexingTime'; public function testGetDefaultSettings(): void { @@ -58,7 +60,8 @@ public function testGetDefaultSettings(): void self::assertEmpty($settingA['sortableAttributes']); self::assertIsIterable($settingA['typoTolerance']); self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingA['typoTolerance'])); - + self::assertSame(self::DEFAULT_FACET_SEARCH, $settingA['facetSearch']); + self::assertSame(self::DEFAULT_PREFIX_SEARCH, $settingA['prefixSearch']); self::assertSame(self::DEFAULT_RANKING_RULES, $settingB['rankingRules']); self::assertNull($settingB['distinctAttribute']); self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settingB['searchableAttributes']); @@ -73,6 +76,8 @@ public function testGetDefaultSettings(): void self::assertEmpty($settingB['sortableAttributes']); self::assertIsIterable($settingB['typoTolerance']); self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingB['typoTolerance'])); + self::assertSame(self::DEFAULT_FACET_SEARCH, $settingB['facetSearch']); + self::assertSame(self::DEFAULT_PREFIX_SEARCH, $settingB['prefixSearch']); } public function testUpdateSettings(): void @@ -82,6 +87,8 @@ public function testUpdateSettings(): void 'distinctAttribute' => 'title', 'rankingRules' => ['title:asc', 'typo'], 'stopWords' => ['the'], + 'facetSearch' => false, + 'prefixSearch' => 'disabled', ]); $this->assertIsValidPromise($promise); $index->waitForTask($promise['taskUid']); @@ -102,6 +109,8 @@ public function testUpdateSettings(): void self::assertIsArray($settings['sortableAttributes']); self::assertEmpty($settings['sortableAttributes']); self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance'])); + self::assertFalse($settings['facetSearch']); + self::assertSame('disabled', $settings['prefixSearch']); } public function testUpdateSettingsWithoutOverwritingThem(): void @@ -184,6 +193,8 @@ public function testResetSettings(): void self::assertIsArray($settings['sortableAttributes']); self::assertEmpty($settings['sortableAttributes']); self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance'])); + self::assertSame(self::DEFAULT_FACET_SEARCH, $settings['facetSearch']); + self::assertSame(self::DEFAULT_PREFIX_SEARCH, $settings['prefixSearch']); } // Here the test to prevent https://github.com/meilisearch/meilisearch-php/issues/204.