Skip to content

Commit

Permalink
Merge #574
Browse files Browse the repository at this point in the history
574: Changes related to the next Meilisearch release (v1.4.0) r=curquiza a=alallema

related to: meilisearch/integration-guides#286

Co-authored-by: alallema <[email protected]>
Co-authored-by: Bruno Casali <[email protected]>
Co-authored-by: Clémentine U. - curqui <[email protected]>
  • Loading branch information
4 people authored Sep 25, 2023
2 parents 63b277c + 3c3a450 commit 8d808c4
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -677,3 +677,21 @@ multi_search_1: |-
->setIndexUid('movie_ratings')
->setQuery('us')
]);
get_dictionary_1: |-
$client->index('books')->getDictionary();
update_dictionary_1: |-
$client->index('books')->updateDictionary(['J. R. R.', 'W. E. B.']);
reset_dictionary_1: |-
$client->index('books')->resetDictionary();
get_separator_tokens_1: |-
$client->index('articles')->getSeparatorTokens();
update_separator_tokens_1: |-
$client->index('articles')->updateSeparatorTokens(['|', '&hellip;']);
reset_separator_tokens_1: |-
$client->index('articles')->resetSeparatorTokens();
get_non_separator_tokens_1: |-
$client->index('articles')->getNonSeparatorTokens();
update_non_separator_tokens_1: |-
$client->index('articles')->updateNonSeparatorTokens(['@', '#']);
reset_non_separator_tokens_1: |-
$client->index('articles')->resetNonSeparatorTokens();
66 changes: 66 additions & 0 deletions src/Endpoints/Delegates/HandlesSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,70 @@ public function resetTypoTolerance(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/typo-tolerance');
}

// Settings - Word dictionary

/**
* @return list<non-empty-string>
*/
public function getDictionary(): array
{
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/dictionary');
}

/**
* @param list<non-empty-string> $wordDictionary
*/
public function updateDictionary(array $wordDictionary): array
{
return $this->http->put(self::PATH.'/'.$this->uid.'/settings/dictionary', $wordDictionary);
}

public function resetDictionary(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/dictionary');
}

// Settings - Separator tokens

public function getSeparatorTokens(): array
{
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/separator-tokens');
}

/**
* @param list<non-empty-string> $separatorTokens
*/
public function updateSeparatorTokens(array $separatorTokens): array
{
return $this->http->put(self::PATH.'/'.$this->uid.'/settings/separator-tokens', $separatorTokens);
}

public function resetSeparatorTokens(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/separator-tokens');
}

// Settings - Non-Separator tokens

/**
* @return list<non-empty-string>
*/
public function getNonSeparatorTokens(): array
{
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/non-separator-tokens');
}

/**
* @param list<non-empty-string> $nonSeparatorTokens
*/
public function updateNonSeparatorTokens(array $nonSeparatorTokens): array
{
return $this->http->put(self::PATH.'/'.$this->uid.'/settings/non-separator-tokens', $nonSeparatorTokens);
}

public function resetNonSeparatorTokens(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/non-separator-tokens');
}
}
1 change: 1 addition & 0 deletions tests/Endpoints/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function testIndexGetSettings(): void
],
$this->index->getTypoTolerance(),
);
$this->assertSame([], $this->index->getDictionary());
}

public function testGetPrimaryKey(): void
Expand Down
55 changes: 55 additions & 0 deletions tests/Settings/NonSeparatorTokensTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Tests\Settings;

use Meilisearch\Endpoints\Indexes;
use Tests\TestCase;

final class NonSeparatorTokensTest extends TestCase
{
private Indexes $index;

public const DEFAULT_NON_SEPARATOR_TOKENS = [];

protected function setUp(): void
{
parent::setUp();
$this->index = $this->createEmptyIndex($this->safeIndexName());
}

public function testGetDefaultNonSeparatorTokens(): void
{
$response = $this->index->getNonSeparatorTokens();

$this->assertEquals(self::DEFAULT_NON_SEPARATOR_TOKENS, $response);
}

public function testUpdateNonSeparatorTokens(): void
{
$newNonSeparatorTokens = [
'&sep',
'/',
'|',
];

$promise = $this->index->updateNonSeparatorTokens($newNonSeparatorTokens);

$this->index->waitForTask($promise['taskUid']);

$nonSeparatorTokens = $this->index->getNonSeparatorTokens();

$this->assertEquals($newNonSeparatorTokens, $nonSeparatorTokens);
}

public function testResetNonSeparatorTokens(): void
{
$promise = $this->index->resetNonSeparatorTokens();

$this->index->waitForTask($promise['taskUid']);
$nonSeparatorTokens = $this->index->getNonSeparatorTokens();

$this->assertEquals(self::DEFAULT_NON_SEPARATOR_TOKENS, $nonSeparatorTokens);
}
}
55 changes: 55 additions & 0 deletions tests/Settings/SeparatorTokensTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Tests\Settings;

use Meilisearch\Endpoints\Indexes;
use Tests\TestCase;

final class SeparatorTokensTest extends TestCase
{
private Indexes $index;

public const DEFAULT_SEPARATOR_TOKENS = [];

protected function setUp(): void
{
parent::setUp();
$this->index = $this->createEmptyIndex($this->safeIndexName());
}

public function testGetDefaultSeparatorTokens(): void
{
$response = $this->index->getSeparatorTokens();

$this->assertSame(self::DEFAULT_SEPARATOR_TOKENS, $response);
}

public function testUpdateSeparatorTokens(): void
{
$newSeparatorTokens = [
'&sep',
'/',
'|',
];

$promise = $this->index->updateSeparatorTokens($newSeparatorTokens);

$this->index->waitForTask($promise['taskUid']);

$separatorTokens = $this->index->getSeparatorTokens();

$this->assertSame($newSeparatorTokens, $separatorTokens);
}

public function testResetSeparatorTokens(): void
{
$promise = $this->index->resetSeparatorTokens();

$this->index->waitForTask($promise['taskUid']);
$separatorTokens = $this->index->getSeparatorTokens();

$this->assertSame(self::DEFAULT_SEPARATOR_TOKENS, $separatorTokens);
}
}
54 changes: 54 additions & 0 deletions tests/Settings/WordDictionaryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Tests\Settings;

use Meilisearch\Endpoints\Indexes;
use Tests\TestCase;

final class WordDictionaryTest extends TestCase
{
private Indexes $index;

public const DEFAULT_WORD_DICTIONARY = [];

protected function setUp(): void
{
parent::setUp();
$this->index = $this->createEmptyIndex($this->safeIndexName());
}

public function testGetDefaultWordDictionary(): void
{
$response = $this->index->getDictionary();

$this->assertSame(self::DEFAULT_WORD_DICTIONARY, $response);
}

public function testUpdateWordDictionary(): void
{
$newWordDictionary = [
'J. K.',
'J. R. R.',
];

$promise = $this->index->updateDictionary($newWordDictionary);

$this->index->waitForTask($promise['taskUid']);

$wordDictionary = $this->index->getDictionary();

$this->assertSame($newWordDictionary, $wordDictionary);
}

public function testResetWordDictionary(): void
{
$promise = $this->index->resetDictionary();

$this->index->waitForTask($promise['taskUid']);
$wordDictionary = $this->index->getDictionary();

$this->assertSame(self::DEFAULT_WORD_DICTIONARY, $wordDictionary);
}
}

0 comments on commit 8d808c4

Please sign in to comment.