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

Changes related to the next Meilisearch release (v1.11.0) #683

Merged
merged 12 commits into from
Oct 28, 2024
13 changes: 10 additions & 3 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,14 @@ search_parameter_reference_retrieve_vectors_1: |-
$client->index('INDEX_NAME')->search('kitchen utensils', [
'retrieveVectors' => true,
'hybrid' => [
'embedder': 'default'
'embedder': 'EMBEDDER_NAME'
]
]);
search_parameter_guide_hybrid_1: |-
$client->index('INDEX_NAME')->search('kitchen utensils', [
'hybrid' => [
'semanticRatio' => 0.9,
'embedder' => 'EMBEDDER_NAME'
]
]);
search_parameter_reference_ranking_score_threshold_1: |-
Expand All @@ -742,7 +749,7 @@ distinct_attribute_guide_distinct_parameter_1: |-
search_parameter_guide_matching_strategy_3: |-
$client->index('movies')->search('white shirt', ['matchingStrategy' => 'frequency']);
get_similar_post_1: |-
$similarQuery = new SimilarDocumentsQuery('TARGET_DOCUMENT_ID');
$similarQuery = new SimilarDocumentsQuery('TARGET_DOCUMENT_ID', 'default');
$client->index('INDEX_NAME')->searchSimilarDocuments($similarQuery);
multi_search_federated_1: |-
$client->multiSearch([
Expand All @@ -756,7 +763,7 @@ multi_search_federated_1: |-
(new MultiSearchFederation())
);
search_parameter_reference_locales_1: |-
$client->index('INDEX_NAME')->search('進撃の巨人', [
$client->index('INDEX_NAME')->search('QUERY TEXT IN JAPANESE', [
'locales' => ['jpn']
]);
get_localized_attribute_settings_1: |-
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
name: integration-tests (PHP ${{ matrix.php-version }}) (${{ matrix.http-client }})
services:
meilisearch:
image: getmeili/meilisearch:latest
image: getmeili/meilisearch:v1.11.0
ports:
- '7700:7700'
env:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- ./:/home/package

meilisearch:
image: getmeili/meilisearch:latest
image: getmeili/meilisearch:v1.10.0
ports:
- "7700"
environment:
Expand Down
25 changes: 25 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
cacheResult="false"
colors="true">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory>src/</directory>
</include>
</coverage>
<php>
<env name="MEILISEARCH_URL" value="http://localhost:7700"/>
<env name="MEILISEARCH_API_KEY" value="masterKey"/>
</php>
</phpunit>
40 changes: 39 additions & 1 deletion src/Contracts/MultiSearchFederation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class MultiSearchFederation
*/
private ?int $offset = null;

/**
* @var array<non-empty-string, list<non-empty-string>>|null
*/
private ?array $facetsByIndex = null;

/**
* @var array{maxValuesPerFacet: positive-int}|null
*/
private ?array $mergeFacets = null;

/**
* @param non-negative-int $limit
*
Expand All @@ -40,17 +50,45 @@ public function setOffset(int $offset): self
return $this;
}

/**
* @param array<non-empty-string, list<non-empty-string>> $facetsByIndex
*
* @return $this
*/
public function setFacetsByIndex(array $facetsByIndex): self
{
$this->facetsByIndex = $facetsByIndex;

return $this;
}

/**
* @param array{maxValuesPerFacet: positive-int} $mergeFacets
*
* @return $this
*/
public function setMergeFacets(array $mergeFacets): self
{
$this->mergeFacets = $mergeFacets;

return $this;
}

/**
* @return array{
* limit?: non-negative-int,
* offset?: non-negative-int
* offset?: non-negative-int,
* facetsByIndex?: array<non-empty-string, list<non-empty-string>>,
* mergeFacets?: array{maxValuesPerFacet: positive-int},
* }
*/
public function toArray(): array
{
return array_filter([
'limit' => $this->limit,
'offset' => $this->offset,
'facetsByIndex' => $this->facetsByIndex,
'mergeFacets' => $this->mergeFacets,
], static function ($item) { return null !== $item; });
}
}
32 changes: 11 additions & 21 deletions src/Contracts/SimilarDocumentsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class SimilarDocumentsQuery
*/
private $id;

/**
* @var non-empty-string
*/
private string $embedder;

/**
* @var non-negative-int|null
*/
Expand All @@ -21,11 +26,6 @@ class SimilarDocumentsQuery
*/
private ?int $limit = null;

/**
* @var non-empty-string|null
*/
private ?string $embedder = null;

/**
* @var list<non-empty-string>|null
*/
Expand All @@ -48,11 +48,13 @@ class SimilarDocumentsQuery
private $rankingScoreThreshold;

/**
* @param int|string $id
* @param int|string $id
* @param non-empty-string $embedder
*/
public function __construct($id)
public function __construct($id, string $embedder)
{
$this->id = $id;
$this->embedder = $embedder;
}

/**
Expand Down Expand Up @@ -91,18 +93,6 @@ public function setFilter(array $filter): self
return $this;
}

/**
* @param non-empty-string $embedder
*
* @return $this
*/
public function setEmbedder(string $embedder): self
{
$this->embedder = $embedder;

return $this;
}

/**
* @param list<non-empty-string> $attributesToRetrieve an array of attribute names to retrieve
*
Expand Down Expand Up @@ -166,10 +156,10 @@ public function setRankingScoreThreshold($rankingScoreThreshold): self
/**
* @return array{
* id: int|string,
* embedder: non-empty-string,
* offset?: non-negative-int,
* limit?: positive-int,
* filter?: array<int, array<int, string>|string>,
* embedder?: non-empty-string,
* attributesToRetrieve?: list<non-empty-string>,
* showRankingScore?: bool,
* showRankingScoreDetails?: bool,
Expand All @@ -181,10 +171,10 @@ public function toArray(): array
{
return array_filter([
'id' => $this->id,
'embedder' => $this->embedder,
'offset' => $this->offset,
'limit' => $this->limit,
'filter' => $this->filter,
'embedder' => $this->embedder,
'attributesToRetrieve' => $this->attributesToRetrieve,
'showRankingScore' => $this->showRankingScore,
'showRankingScoreDetails' => $this->showRankingScoreDetails,
Expand Down
14 changes: 14 additions & 0 deletions tests/Contracts/MultiSearchFederationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ public function testSetOffset(): void

self::assertSame(['offset' => 5], $data->toArray());
}

public function testSetFacetsByIndex(): void
{
$data = (new MultiSearchFederation())->setFacetsByIndex(['books' => ['author', 'genre']]);

self::assertSame(['facetsByIndex' => ['books' => ['author', 'genre']]], $data->toArray());
}

public function testSetMergeFacets(): void
{
$data = (new MultiSearchFederation())->setMergeFacets(['maxValuesPerFacet' => 10]);

self::assertSame(['mergeFacets' => ['maxValuesPerFacet' => 10]], $data->toArray());
}
}
52 changes: 23 additions & 29 deletions tests/Contracts/SimilarDocumentsQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,48 @@
final class SimilarDocumentsQueryTest extends TestCase
{
/**
* @param int|string $id
* @param int|string $id
* @param non-empty-string $embedder
*
* @testWith [123]
* ["test"]
* @testWith [123, "default"]
* ["test", "manual"]
*/
public function testConstruct($id): void
public function testConstruct($id, string $embedder): void
{
$data = new SimilarDocumentsQuery($id);
$data = new SimilarDocumentsQuery($id, $embedder);

self::assertSame(['id' => $id], $data->toArray());
self::assertSame(['id' => $id, 'embedder' => $embedder], $data->toArray());
}

public function testSetOffset(): void
{
$data = (new SimilarDocumentsQuery('test'))->setOffset(66);
$data = (new SimilarDocumentsQuery('test', 'default'))->setOffset(66);

self::assertSame(['id' => 'test', 'offset' => 66], $data->toArray());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'offset' => 66], $data->toArray());
}

public function testSetLimit(): void
{
$data = (new SimilarDocumentsQuery('test'))->setLimit(50);
$data = (new SimilarDocumentsQuery('test', 'default'))->setLimit(50);

self::assertSame(['id' => 'test', 'limit' => 50], $data->toArray());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'limit' => 50], $data->toArray());
}

public function testSetFilter(): void
{
$data = (new SimilarDocumentsQuery('test'))->setFilter([
$data = (new SimilarDocumentsQuery('test', 'default'))->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());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'filter' => [['genres = horror', 'genres = mystery'], "director = 'Jordan Peele'"]], $data->toArray());
}

public function testSetAttributesToRetrieve(): void
{
$data = (new SimilarDocumentsQuery('test'))->setAttributesToRetrieve(['name', 'price']);
$data = (new SimilarDocumentsQuery('test', 'default'))->setAttributesToRetrieve(['name', 'price']);

self::assertSame(['id' => 'test', 'attributesToRetrieve' => ['name', 'price']], $data->toArray());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'attributesToRetrieve' => ['name', 'price']], $data->toArray());
}

/**
Expand All @@ -66,9 +60,9 @@ public function testSetAttributesToRetrieve(): void
*/
public function testSetShowRankingScore(bool $showRankingScore): void
{
$data = (new SimilarDocumentsQuery('test'))->setShowRankingScore($showRankingScore);
$data = (new SimilarDocumentsQuery('test', 'default'))->setShowRankingScore($showRankingScore);

self::assertSame(['id' => 'test', 'showRankingScore' => $showRankingScore], $data->toArray());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'showRankingScore' => $showRankingScore], $data->toArray());
}

/**
Expand All @@ -77,9 +71,9 @@ public function testSetShowRankingScore(bool $showRankingScore): void
*/
public function testSetShowRankingScoreDetails(bool $showRankingScoreDetails): void
{
$data = (new SimilarDocumentsQuery('test'))->setShowRankingScoreDetails($showRankingScoreDetails);
$data = (new SimilarDocumentsQuery('test', 'default'))->setShowRankingScoreDetails($showRankingScoreDetails);

self::assertSame(['id' => 'test', 'showRankingScoreDetails' => $showRankingScoreDetails], $data->toArray());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'showRankingScoreDetails' => $showRankingScoreDetails], $data->toArray());
}

/**
Expand All @@ -88,9 +82,9 @@ public function testSetShowRankingScoreDetails(bool $showRankingScoreDetails): v
*/
public function testSetRetrieveVectors(bool $retrieveVectors): void
{
$data = (new SimilarDocumentsQuery('test'))->setRetrieveVectors($retrieveVectors);
$data = (new SimilarDocumentsQuery('test', 'default'))->setRetrieveVectors($retrieveVectors);

self::assertSame(['id' => 'test', 'retrieveVectors' => $retrieveVectors], $data->toArray());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'retrieveVectors' => $retrieveVectors], $data->toArray());
}

/**
Expand All @@ -101,8 +95,8 @@ public function testSetRetrieveVectors(bool $retrieveVectors): void
*/
public function testSetRankingScoreThreshold($rankingScoreThreshold): void
{
$data = (new SimilarDocumentsQuery('test'))->setRankingScoreThreshold($rankingScoreThreshold);
$data = (new SimilarDocumentsQuery('test', 'default'))->setRankingScoreThreshold($rankingScoreThreshold);

self::assertSame(['id' => 'test', 'rankingScoreThreshold' => $rankingScoreThreshold], $data->toArray());
self::assertSame(['id' => 'test', 'embedder' => 'default', 'rankingScoreThreshold' => $rankingScoreThreshold], $data->toArray());
}
}
3 changes: 2 additions & 1 deletion tests/Endpoints/MultiSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ public function testFederation(): void
// By setting the weight to 0.9 this query should appear second
->setFederationOptions((new FederationOptions())->setWeight(0.9)),
],
(new MultiSearchFederation())->setLimit(2)
(new MultiSearchFederation())->setLimit(2)->setFacetsByIndex([$this->booksIndex->getUid() => ['genre'], $this->songsIndex->getUid() => ['duration-float']])->setMergeFacets(['maxValuesPerFacet' => 10])
);

self::assertArrayHasKey('hits', $response);
self::assertArrayHasKey('processingTimeMs', $response);
self::assertArrayHasKey('limit', $response);
self::assertArrayHasKey('offset', $response);
self::assertArrayHasKey('estimatedTotalHits', $response);
self::assertArrayHasKey('facetDistribution', $response);
self::assertCount(2, $response['hits']);
self::assertSame(2, $response['limit']);
self::assertSame(0, $response['offset']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Endpoints/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,12 @@ public function testVectorSearch(): void
$this->assertIsValidPromise($promise);
$index->waitForTask($promise['taskUid']);

$response = $index->search('', ['vector' => [-0.5, 0.3, 0.85], 'hybrid' => ['semanticRatio' => 1.0]]);
$response = $index->search('', ['vector' => [-0.5, 0.3, 0.85], 'hybrid' => ['semanticRatio' => 1.0, 'embedder' => 'manual']]);

self::assertSame(5, $response->getSemanticHitCount());
self::assertArrayNotHasKey('_vectors', $response->getHit(0));

$response = $index->search('', ['vector' => [-0.5, 0.3, 0.85], 'hybrid' => ['semanticRatio' => 1.0], 'retrieveVectors' => true]);
$response = $index->search('', ['vector' => [-0.5, 0.3, 0.85], 'hybrid' => ['semanticRatio' => 1.0, 'embedder' => 'manual'], 'retrieveVectors' => true]);

self::assertSame(5, $response->getSemanticHitCount());
self::assertArrayHasKey('_vectors', $response->getHit(0));
Expand Down
Loading
Loading