Skip to content

Commit

Permalink
Merge pull request #702 from meilisearch/feat/add-v1.12-settings
Browse files Browse the repository at this point in the history
Add `prefixSearch` and `facetSearch` index settings
  • Loading branch information
Strift authored Dec 6, 2024
2 parents 77cd241 + a05224a commit 3e0a026
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/Endpoints/Delegates/HandlesSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
49 changes: 49 additions & 0 deletions tests/Settings/FacetSearchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Tests\Settings;

use Tests\TestCase;

final class FacetSearchTest extends TestCase
{
public function testGetDefaultFacetSearch(): void
{
$index = $this->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);
}
}
49 changes: 49 additions & 0 deletions tests/Settings/PrefixSearchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Tests\Settings;

use Tests\TestCase;

final class PrefixSearchTest extends TestCase
{
public function testGetDefaultPrefixSearch(): void
{
$index = $this->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);
}
}
13 changes: 12 additions & 1 deletion tests/Settings/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']);
Expand All @@ -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
Expand All @@ -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']);
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3e0a026

Please sign in to comment.