Skip to content

Commit f1788b7

Browse files
meili-bors[bot]meili-botStrift
authored
Merge #731
731: Changes related to the next Meilisearch release (v1.14.0) r=curquiza a=meili-bot Related to this issue: meilisearch/integration-guides#315 This PR: - gathers the changes related to the next Meilisearch release (v1.14.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v1.14.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.14.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Laurent Cazanove <[email protected]>
2 parents 16a3c31 + 4cdff49 commit f1788b7

File tree

10 files changed

+213
-9
lines changed

10 files changed

+213
-9
lines changed

.code-samples.meilisearch.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,17 @@ get_filterable_attributes_1: |-
262262
$client->index('movies')->getFilterableAttributes();
263263
update_filterable_attributes_1: |-
264264
$client->index('movies')->updateFilterableAttributes([
265-
'genres',
266-
'director'
265+
'author',
266+
[
267+
'attributePatterns' => ['genres'],
268+
'features' => [
269+
'facetSearch' => true,
270+
'filter' => [
271+
'equality' => true,
272+
'comparison' => false,
273+
],
274+
],
275+
],
267276
]);
268277
reset_filterable_attributes_1: |-
269278
$client->index('movies')->resetFilterableAttributes();

src/Contracts/DocumentsQuery.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class DocumentsQuery
2828

2929
private ?bool $retrieveVectors = null;
3030

31+
/**
32+
* @var list<non-empty-string|int>|null
33+
*/
34+
private ?array $ids = null;
35+
3136
/**
3237
* @param non-negative-int $offset
3338
*
@@ -90,6 +95,18 @@ public function setRetrieveVectors(?bool $retrieveVectors): self
9095
return $this;
9196
}
9297

98+
/**
99+
* @param list<non-empty-string|int> $ids Array of document IDs
100+
*
101+
* @return $this
102+
*/
103+
public function setIds(array $ids): self
104+
{
105+
$this->ids = $ids;
106+
107+
return $this;
108+
}
109+
93110
/**
94111
* Checks if the $filter attribute has been set.
95112
*
@@ -106,7 +123,8 @@ public function hasFilter(): bool
106123
* limit?: non-negative-int,
107124
* fields?: non-empty-list<string>|non-empty-string,
108125
* filter?: list<non-empty-string|list<non-empty-string>>,
109-
* retrieveVectors?: 'true'|'false'
126+
* retrieveVectors?: 'true'|'false',
127+
* ids?: string
110128
* }
111129
*/
112130
public function toArray(): array
@@ -117,6 +135,7 @@ public function toArray(): array
117135
'fields' => $this->getFields(),
118136
'filter' => $this->filter,
119137
'retrieveVectors' => (null !== $this->retrieveVectors ? ($this->retrieveVectors ? 'true' : 'false') : null),
138+
'ids' => ($this->ids ?? []) !== [] ? implode(',', $this->ids) : null,
120139
], static function ($item) { return null !== $item; });
121140
}
122141

src/Contracts/FacetSearchQuery.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class FacetSearchQuery
3333
*/
3434
private ?array $attributesToSearchOn = null;
3535

36+
private ?bool $exhaustiveFacetsCount = null;
37+
3638
/**
3739
* @return $this
3840
*/
@@ -99,14 +101,25 @@ public function setAttributesToSearchOn(array $attributesToSearchOn): self
99101
return $this;
100102
}
101103

104+
/**
105+
* @return $this
106+
*/
107+
public function setExhaustiveFacetsCount(bool $exhaustiveFacetsCount): self
108+
{
109+
$this->exhaustiveFacetsCount = $exhaustiveFacetsCount;
110+
111+
return $this;
112+
}
113+
102114
/**
103115
* @return array{
104116
* facetName?: non-empty-string,
105117
* facetQuery?: non-empty-string,
106118
* q?: string,
107119
* filter?: list<non-empty-string|list<non-empty-string>>,
108120
* matchingStrategy?: 'last'|'all'|'frequency'|null,
109-
* attributesToSearchOn?: non-empty-list<non-empty-string>
121+
* attributesToSearchOn?: non-empty-list<non-empty-string>,
122+
* exhaustiveFacetsCount?: bool
110123
* }
111124
*/
112125
public function toArray(): array
@@ -118,6 +131,7 @@ public function toArray(): array
118131
'filter' => $this->filter,
119132
'matchingStrategy' => $this->matchingStrategy,
120133
'attributesToSearchOn' => $this->attributesToSearchOn,
134+
'exhaustiveFacetsCount' => $this->exhaustiveFacetsCount,
121135
], static function ($item) { return null !== $item; });
122136
}
123137
}

src/Endpoints/Delegates/HandlesSettings.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,26 @@ public function resetSynonyms(): array
222222
// Settings - Filterable Attributes
223223

224224
/**
225-
* @return list<non-empty-string>
225+
* @return list<non-empty-string|array{
226+
* attributePatterns: list<non-empty-string>,
227+
* features?: array{
228+
* facetSearch: bool,
229+
* filter: array{equality: bool, comparison: bool}
230+
* }
231+
* }>
226232
*/
227233
public function getFilterableAttributes(): array
228234
{
229235
return $this->http->get(self::PATH.'/'.$this->uid.'/settings/filterable-attributes');
230236
}
231237

232238
/**
233-
* @param list<non-empty-string> $filterableAttributes
239+
* @param list<non-empty-string|array{
240+
* attributePatterns: list<non-empty-string>,
241+
* features?: array{facetSearch: bool, filter: array{equality: bool, comparison: bool}}
242+
* }> $filterableAttributes
243+
*
244+
* Note: When attributePatterns contains '_geo', the features field is ignored
234245
*/
235246
public function updateFilterableAttributes(array $filterableAttributes): array
236247
{

tests/Contracts/DocumentsQueryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,29 @@ public function testSetOffset(): void
3636

3737
self::assertSame(['offset' => 5], $data->toArray());
3838
}
39+
40+
/**
41+
* @dataProvider idsProvider
42+
*/
43+
public function testSetIds(array $input, ?string $expected): void
44+
{
45+
$data = (new DocumentsQuery())->setIds($input);
46+
$result = $data->toArray();
47+
48+
if (null === $expected) {
49+
self::assertArrayNotHasKey('ids', $result);
50+
} else {
51+
self::assertSame($expected, $result['ids']);
52+
}
53+
}
54+
55+
public static function idsProvider(): array
56+
{
57+
return [
58+
'string array' => [['1', '2', '3'], '1,2,3'],
59+
'integer array' => [[1, 2, 3], '1,2,3'],
60+
'mixed array' => [['1', 2, '3'], '1,2,3'],
61+
'empty array' => [[], null],
62+
];
63+
}
3964
}

tests/Contracts/FacetSearchQueryTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ public function testSetAttributesToSearchOn(): void
6464

6565
self::assertSame(['attributesToSearchOn' => ['overview']], $data->toArray());
6666
}
67+
68+
public function testSetExhaustiveFacetsCount(): void
69+
{
70+
$data = (new FacetSearchQuery())->setExhaustiveFacetsCount(true);
71+
72+
self::assertSame(['exhaustiveFacetsCount' => true], $data->toArray());
73+
}
6774
}

tests/Endpoints/BatchesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testGetOneBatch(): void
6565
self::assertArrayHasKey('status', $response['stats']);
6666
self::assertArrayHasKey('types', $response['stats']);
6767
self::assertArrayHasKey('indexUids', $response['stats']);
68+
self::assertArrayHasKey('progressTrace', $response['stats']);
6869
self::assertArrayHasKey('duration', $response);
6970
self::assertArrayHasKey('startedAt', $response);
7071
self::assertArrayHasKey('finishedAt', $response);

tests/Endpoints/DocumentsTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ public function testGetSingleDocumentWithStringDocumentId(): void
200200
self::assertSame($stringDocumentId, $response['id']);
201201
}
202202

203+
public function testGetMultipleDocumentsByIds(): void
204+
{
205+
$index = $this->createEmptyIndex($this->safeIndexName('movies'));
206+
$response = $index->addDocuments(self::DOCUMENTS);
207+
$index->waitForTask($response['taskUid']);
208+
$documentIds = [1, 2];
209+
$response = $index->getDocuments((new DocumentsQuery())->setIds($documentIds));
210+
211+
$returnedIds = array_column($response->getResults(), 'id');
212+
foreach ($documentIds as $id) {
213+
self::assertContains($id, $returnedIds);
214+
}
215+
}
216+
203217
public function testReplaceDocuments(): void
204218
{
205219
$index = $this->createEmptyIndex($this->safeIndexName('movies'));

tests/Settings/EmbeddersTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Tests\Settings;
66

77
use Meilisearch\Endpoints\Indexes;
8+
use Meilisearch\Http\Client;
89
use Tests\TestCase;
910

1011
final class EmbeddersTest extends TestCase
@@ -51,4 +52,54 @@ public function testResetEmbedders(): void
5152

5253
self::assertSame(self::DEFAULT_EMBEDDER, $embedders);
5354
}
55+
56+
public function testHuggingFacePooling(): void
57+
{
58+
$embedder = [
59+
'source' => 'huggingFace',
60+
'model' => 'sentence-transformers/all-MiniLM-L6-v2',
61+
'pooling' => 'useModel',
62+
];
63+
64+
$promise = $this->index->updateEmbedders([
65+
'embedder_name' => [
66+
'source' => 'huggingFace',
67+
'model' => 'sentence-transformers/all-MiniLM-L6-v2',
68+
'pooling' => 'useModel',
69+
],
70+
]);
71+
72+
$this->assertIsValidPromise($promise);
73+
$this->index->waitForTask($promise['taskUid']);
74+
75+
$embedders = $this->index->getEmbedders();
76+
77+
self::assertSame($embedder['source'], $embedders['embedder_name']['source']);
78+
self::assertSame($embedder['model'], $embedders['embedder_name']['model']);
79+
self::assertSame($embedder['pooling'], $embedders['embedder_name']['pooling']);
80+
}
81+
82+
public function testCompositeEmbedder(): void
83+
{
84+
$http = new Client($this->host, getenv('MEILISEARCH_API_KEY'));
85+
$http->patch('/experimental-features', ['compositeEmbedders' => true]);
86+
87+
$embedder = [
88+
'source' => 'composite',
89+
'searchEmbedder' => [
90+
'source' => 'huggingFace',
91+
'model' => 'sentence-transformers/all-MiniLM-L6-v2',
92+
],
93+
'indexingEmbedder' => [
94+
'source' => 'huggingFace',
95+
'model' => 'sentence-transformers/all-MiniLM-L6-v2',
96+
],
97+
];
98+
99+
$promise = $this->index->updateEmbedders([
100+
'embedder_name' => $embedder,
101+
]);
102+
103+
$this->assertIsValidPromise($promise);
104+
}
54105
}

tests/Settings/FilterableAttributesTest.php

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ public function testGetDefaultFilterableAttributes(): void
1919

2020
public function testUpdateFilterableAttributes(): void
2121
{
22-
$newAttributes = ['title'];
22+
$expectedAttributes = ['title'];
2323
$index = $this->createEmptyIndex($this->safeIndexName());
2424

25-
$promise = $index->updateFilterableAttributes($newAttributes);
25+
$promise = $index->updateFilterableAttributes($expectedAttributes);
2626

2727
$this->assertIsValidPromise($promise);
2828
$index->waitForTask($promise['taskUid']);
2929

3030
$filterableAttributes = $index->getFilterableAttributes();
3131

32-
self::assertSame($newAttributes, $filterableAttributes);
32+
self::assertSame($expectedAttributes, $filterableAttributes);
3333
}
3434

3535
public function testResetFilterableAttributes(): void
@@ -49,4 +49,57 @@ public function testResetFilterableAttributes(): void
4949
$filterableAttributes = $index->getFilterableAttributes();
5050
self::assertEmpty($filterableAttributes);
5151
}
52+
53+
public function testUpdateGranularFilterableAttributes(): void
54+
{
55+
$index = $this->createEmptyIndex($this->safeIndexName());
56+
57+
$expectedAttributes = [
58+
'author',
59+
[
60+
'attributePatterns' => ['title'],
61+
'features' => [
62+
'facetSearch' => true,
63+
'filter' => [
64+
'equality' => true,
65+
'comparison' => false,
66+
],
67+
],
68+
],
69+
];
70+
71+
$promise = $index->updateFilterableAttributes($expectedAttributes);
72+
$this->assertIsValidPromise($promise);
73+
74+
$index->waitForTask($promise['taskUid']);
75+
$filterableAttributes = $index->getFilterableAttributes();
76+
self::assertSame($expectedAttributes, $filterableAttributes);
77+
}
78+
79+
public function testUpdateGeoWithGranularFilterableAttributes(): void
80+
{
81+
$index = $this->createEmptyIndex($this->safeIndexName());
82+
83+
$promise = $index->updateFilterableAttributes([
84+
[
85+
'attributePatterns' => ['_geo'],
86+
],
87+
]);
88+
$this->assertIsValidPromise($promise);
89+
90+
$index->waitForTask($promise['taskUid']);
91+
$filterableAttributes = $index->getFilterableAttributes();
92+
self::assertSame([
93+
[
94+
'attributePatterns' => ['_geo'],
95+
'features' => [
96+
'facetSearch' => false,
97+
'filter' => [
98+
'equality' => true,
99+
'comparison' => false,
100+
],
101+
],
102+
],
103+
], $filterableAttributes);
104+
}
52105
}

0 commit comments

Comments
 (0)