-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
675: Add `rankingScoreThreshold` to `SimilarDocumentsQuery` r=brunoocasali a=norkunas # Pull Request ## Related issue Fixes #671 ## What does this PR do? - ... ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [X] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Tomas <[email protected]>
- Loading branch information
Showing
2 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Contracts; | ||
|
||
use Meilisearch\Contracts\SimilarDocumentsQuery; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SimilarDocumentsQueryTest extends TestCase | ||
{ | ||
/** | ||
* @param int|string $id | ||
* | ||
* @testWith [123] | ||
* ["test"] | ||
*/ | ||
public function testConstruct($id): void | ||
{ | ||
$data = new SimilarDocumentsQuery($id); | ||
|
||
self::assertSame(['id' => $id], $data->toArray()); | ||
} | ||
|
||
public function testSetOffset(): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setOffset(66); | ||
|
||
self::assertSame(['id' => 'test', 'offset' => 66], $data->toArray()); | ||
} | ||
|
||
public function testSetLimit(): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setLimit(50); | ||
|
||
self::assertSame(['id' => 'test', 'limit' => 50], $data->toArray()); | ||
} | ||
|
||
public function testSetFilter(): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setFilter([ | ||
['genres = horror', 'genres = mystery'], | ||
"director = 'Jordan Peele'", | ||
]); | ||
|
||
self::assertSame(['id' => 'test', 'filter' => [['genres = horror', 'genres = mystery'], "director = 'Jordan Peele'"]], $data->toArray()); | ||
} | ||
|
||
public function testSetEmbedder(): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setEmbedder('default'); | ||
|
||
self::assertSame(['id' => 'test', 'embedder' => 'default'], $data->toArray()); | ||
} | ||
|
||
public function testSetAttributesToRetrieve(): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setAttributesToRetrieve(['name', 'price']); | ||
|
||
self::assertSame(['id' => 'test', 'attributesToRetrieve' => ['name', 'price']], $data->toArray()); | ||
} | ||
|
||
/** | ||
* @testWith [false] | ||
* [true] | ||
*/ | ||
public function testSetShowRankingScore(bool $showRankingScore): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setShowRankingScore($showRankingScore); | ||
|
||
self::assertSame(['id' => 'test', 'showRankingScore' => $showRankingScore], $data->toArray()); | ||
} | ||
|
||
/** | ||
* @testWith [false] | ||
* [true] | ||
*/ | ||
public function testSetShowRankingScoreDetails(bool $showRankingScoreDetails): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setShowRankingScoreDetails($showRankingScoreDetails); | ||
|
||
self::assertSame(['id' => 'test', 'showRankingScoreDetails' => $showRankingScoreDetails], $data->toArray()); | ||
} | ||
|
||
/** | ||
* @testWith [false] | ||
* [true] | ||
*/ | ||
public function testSetRetrieveVectors(bool $retrieveVectors): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setRetrieveVectors($retrieveVectors); | ||
|
||
self::assertSame(['id' => 'test', 'retrieveVectors' => $retrieveVectors], $data->toArray()); | ||
} | ||
|
||
/** | ||
* @testWith [123] | ||
* [0.123] | ||
* | ||
* @param int|float $rankingScoreThreshold | ||
*/ | ||
public function testSetRankingScoreThreshold($rankingScoreThreshold): void | ||
{ | ||
$data = (new SimilarDocumentsQuery('test'))->setRankingScoreThreshold($rankingScoreThreshold); | ||
|
||
self::assertSame(['id' => 'test', 'rankingScoreThreshold' => $rankingScoreThreshold], $data->toArray()); | ||
} | ||
} |