Skip to content

Commit 3e0a026

Browse files
authored
Merge pull request #702 from meilisearch/feat/add-v1.12-settings
Add `prefixSearch` and `facetSearch` index settings
2 parents 77cd241 + a05224a commit 3e0a026

File tree

4 files changed

+166
-1
lines changed

4 files changed

+166
-1
lines changed

src/Endpoints/Delegates/HandlesSettings.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,60 @@ public function resetEmbedders(): array
421421
{
422422
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/embedders');
423423
}
424+
425+
// Settings - Facet Search
426+
427+
/**
428+
* @since Meilisearch v1.12.0
429+
*/
430+
public function getFacetSearch(): bool
431+
{
432+
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/facet-search');
433+
}
434+
435+
/**
436+
* @since Meilisearch v1.12.0
437+
*/
438+
public function updateFacetSearch(bool $facetSearch): array
439+
{
440+
return $this->http->put(self::PATH.'/'.$this->uid.'/settings/facet-search', $facetSearch);
441+
}
442+
443+
/**
444+
* @since Meilisearch v1.12.0
445+
*/
446+
public function resetFacetSearch(): array
447+
{
448+
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/facet-search');
449+
}
450+
451+
// Settings - Prefix Search
452+
453+
/**
454+
* @return 'indexingTime'|'disabled'
455+
*
456+
* @since Meilisearch v1.12.0
457+
*/
458+
public function getPrefixSearch(): string
459+
{
460+
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/prefix-search');
461+
}
462+
463+
/**
464+
* @param 'indexingTime'|'disabled' $prefixSearch
465+
*
466+
* @since Meilisearch v1.12.0
467+
*/
468+
public function updatePrefixSearch(string $prefixSearch): array
469+
{
470+
return $this->http->put(self::PATH.'/'.$this->uid.'/settings/prefix-search', $prefixSearch);
471+
}
472+
473+
/**
474+
* @since Meilisearch v1.12.0
475+
*/
476+
public function resetPrefixSearch(): array
477+
{
478+
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/prefix-search');
479+
}
424480
}

tests/Settings/FacetSearchTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Settings;
6+
7+
use Tests\TestCase;
8+
9+
final class FacetSearchTest extends TestCase
10+
{
11+
public function testGetDefaultFacetSearch(): void
12+
{
13+
$index = $this->createEmptyIndex($this->safeIndexName());
14+
15+
$facetSearch = $index->getFacetSearch();
16+
17+
self::assertTrue($facetSearch);
18+
}
19+
20+
public function testUpdateFacetSearch(): void
21+
{
22+
$index = $this->createEmptyIndex($this->safeIndexName());
23+
24+
$promise = $index->updateFacetSearch(false);
25+
26+
$this->assertIsValidPromise($promise);
27+
$index->waitForTask($promise['taskUid']);
28+
29+
$facetSearch = $index->getFacetSearch();
30+
self::assertFalse($facetSearch);
31+
}
32+
33+
public function testResetFacetSearch(): void
34+
{
35+
$index = $this->createEmptyIndex($this->safeIndexName());
36+
37+
$promise = $index->updateFacetSearch(false);
38+
$index->waitForTask($promise['taskUid']);
39+
40+
$promise = $index->resetFacetSearch();
41+
42+
$this->assertIsValidPromise($promise);
43+
44+
$index->waitForTask($promise['taskUid']);
45+
46+
$facetSearch = $index->getFacetSearch();
47+
self::assertTrue($facetSearch);
48+
}
49+
}

tests/Settings/PrefixSearchTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Settings;
6+
7+
use Tests\TestCase;
8+
9+
final class PrefixSearchTest extends TestCase
10+
{
11+
public function testGetDefaultPrefixSearch(): void
12+
{
13+
$index = $this->createEmptyIndex($this->safeIndexName());
14+
15+
$prefixSearch = $index->getPrefixSearch();
16+
17+
self::assertSame('indexingTime', $prefixSearch);
18+
}
19+
20+
public function testUpdatePrefixSearch(): void
21+
{
22+
$index = $this->createEmptyIndex($this->safeIndexName());
23+
24+
$promise = $index->updatePrefixSearch('disabled');
25+
26+
$this->assertIsValidPromise($promise);
27+
$index->waitForTask($promise['taskUid']);
28+
29+
$prefixSearch = $index->getPrefixSearch();
30+
self::assertSame('disabled', $prefixSearch);
31+
}
32+
33+
public function testResetPrefixSearch(): void
34+
{
35+
$index = $this->createEmptyIndex($this->safeIndexName());
36+
37+
$promise = $index->updatePrefixSearch('disabled');
38+
$index->waitForTask($promise['taskUid']);
39+
40+
$promise = $index->resetPrefixSearch();
41+
42+
$this->assertIsValidPromise($promise);
43+
44+
$index->waitForTask($promise['taskUid']);
45+
46+
$prefixSearch = $index->getPrefixSearch();
47+
self::assertSame('indexingTime', $prefixSearch);
48+
}
49+
}

tests/Settings/SettingsTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ final class SettingsTest extends TestCase
2929

3030
public const DEFAULT_SEARCHABLE_ATTRIBUTES = ['*'];
3131
public const DEFAULT_DISPLAYED_ATTRIBUTES = ['*'];
32+
public const DEFAULT_FACET_SEARCH = true;
33+
public const DEFAULT_PREFIX_SEARCH = 'indexingTime';
3234

3335
public function testGetDefaultSettings(): void
3436
{
@@ -58,7 +60,8 @@ public function testGetDefaultSettings(): void
5860
self::assertEmpty($settingA['sortableAttributes']);
5961
self::assertIsIterable($settingA['typoTolerance']);
6062
self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingA['typoTolerance']));
61-
63+
self::assertSame(self::DEFAULT_FACET_SEARCH, $settingA['facetSearch']);
64+
self::assertSame(self::DEFAULT_PREFIX_SEARCH, $settingA['prefixSearch']);
6265
self::assertSame(self::DEFAULT_RANKING_RULES, $settingB['rankingRules']);
6366
self::assertNull($settingB['distinctAttribute']);
6467
self::assertSame(self::DEFAULT_SEARCHABLE_ATTRIBUTES, $settingB['searchableAttributes']);
@@ -73,6 +76,8 @@ public function testGetDefaultSettings(): void
7376
self::assertEmpty($settingB['sortableAttributes']);
7477
self::assertIsIterable($settingB['typoTolerance']);
7578
self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settingB['typoTolerance']));
79+
self::assertSame(self::DEFAULT_FACET_SEARCH, $settingB['facetSearch']);
80+
self::assertSame(self::DEFAULT_PREFIX_SEARCH, $settingB['prefixSearch']);
7681
}
7782

7883
public function testUpdateSettings(): void
@@ -82,6 +87,8 @@ public function testUpdateSettings(): void
8287
'distinctAttribute' => 'title',
8388
'rankingRules' => ['title:asc', 'typo'],
8489
'stopWords' => ['the'],
90+
'facetSearch' => false,
91+
'prefixSearch' => 'disabled',
8592
]);
8693
$this->assertIsValidPromise($promise);
8794
$index->waitForTask($promise['taskUid']);
@@ -102,6 +109,8 @@ public function testUpdateSettings(): void
102109
self::assertIsArray($settings['sortableAttributes']);
103110
self::assertEmpty($settings['sortableAttributes']);
104111
self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance']));
112+
self::assertFalse($settings['facetSearch']);
113+
self::assertSame('disabled', $settings['prefixSearch']);
105114
}
106115

107116
public function testUpdateSettingsWithoutOverwritingThem(): void
@@ -184,6 +193,8 @@ public function testResetSettings(): void
184193
self::assertIsArray($settings['sortableAttributes']);
185194
self::assertEmpty($settings['sortableAttributes']);
186195
self::assertSame(self::DEFAULT_TYPO_TOLERANCE, iterator_to_array($settings['typoTolerance']));
196+
self::assertSame(self::DEFAULT_FACET_SEARCH, $settings['facetSearch']);
197+
self::assertSame(self::DEFAULT_PREFIX_SEARCH, $settings['prefixSearch']);
187198
}
188199

189200
// Here the test to prevent https://github.com/meilisearch/meilisearch-php/issues/204.

0 commit comments

Comments
 (0)