Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to configure new prefixSearch and facetSearch index settings #702

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this annotation (everywhere)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say we need it to the point where we should update all the code base. But if it shows up in the generated documentation, then it's useful information for the reader. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

*/
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
Loading