Skip to content

Commit 1554557

Browse files
committed
feat: support Meilisearch 1.18 (queryVector + index renaming)
1 parent e9674e7 commit 1554557

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ create_an_index_1: |-
3131
client.createIndex('movies', { primaryKey: 'id' })
3232
update_an_index_1: |-
3333
client.updateIndex('movies', { primaryKey: 'id' })
34+
rename_an_index_1: |-
35+
client.updateIndex('INDEX_A', { indexUid: 'INDEX_B' })
3436
delete_an_index_1: |-
3537
client.deleteIndex('movies')
3638
swap_indexes_1: |-

src/types/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export type ResultsWrapper<T> = {
141141

142142
export type IndexOptions = {
143143
primaryKey?: string;
144+
indexUid?: string;
144145
};
145146

146147
export type IndexObject = {
@@ -408,6 +409,7 @@ export type SearchResponse<
408409
facetDistribution?: FacetDistribution;
409410
facetStats?: FacetStats;
410411
facetsByIndex?: FacetsByIndex;
412+
queryVector?: number[];
411413
} & (undefined extends S
412414
? Partial<FinitePagination & InfinitePagination>
413415
: true extends IsFinitePagination<NonNullable<S>>

tests/client.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,46 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
566566
ErrorStatusCode.INVALID_SWAP_DUPLICATE_INDEX_FOUND,
567567
);
568568
});
569+
570+
test(`${permission} key: Swap two indexes with rename`, async () => {
571+
const client = await getClient(permission);
572+
const originalUid1 = index.uid;
573+
const originalUid2 = index2.uid;
574+
575+
await client
576+
.index(originalUid1)
577+
.addDocuments([{ id: 1, title: "index_1" }])
578+
.waitTask();
579+
await client
580+
.index(originalUid2)
581+
.addDocuments([{ id: 1, title: "index_2" }])
582+
.waitTask();
583+
584+
const swaps: IndexSwap[] = [
585+
{ indexes: [originalUid1, originalUid2], rename: true },
586+
];
587+
588+
const resolvedTask = await client.swapIndexes(swaps).waitTask();
589+
590+
// Verify the old indexes no longer exist
591+
await expect(client.getIndex(originalUid1)).rejects.toHaveProperty(
592+
"cause.code",
593+
ErrorStatusCode.INDEX_NOT_FOUND,
594+
);
595+
await expect(client.getIndex(originalUid2)).rejects.toHaveProperty(
596+
"cause.code",
597+
ErrorStatusCode.INDEX_NOT_FOUND,
598+
);
599+
600+
// Verify the new indexes exist with swapped content
601+
const docIndex1 = await client.index(originalUid1).getDocument(1);
602+
const docIndex2 = await client.index(originalUid2).getDocument(1);
603+
604+
expect(docIndex1.title).toEqual("index_2");
605+
expect(docIndex2.title).toEqual("index_1");
606+
expect(resolvedTask.type).toEqual("indexSwap");
607+
expect(resolvedTask.details?.swaps).toEqual(swaps);
608+
});
569609
});
570610

571611
describe("Test on base routes", () => {

tests/get_search.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ describe.each([
520520
expect(response).toHaveProperty("hits", expect.any(Array));
521521
expect(response).toHaveProperty("query", "prince");
522522
expect(response.hits[0]).toHaveProperty("_vectors");
523+
expect(response).toHaveProperty("queryVector", expect.any(Array));
523524
});
524525

525526
test(`${permission} key: search without retrieveVectors`, async () => {
@@ -530,6 +531,7 @@ describe.each([
530531
expect(response).toHaveProperty("hits", expect.any(Array));
531532
expect(response).toHaveProperty("query", "prince");
532533
expect(response.hits[0]).not.toHaveProperty("_vectors");
534+
expect(response).not.toHaveProperty("queryVector");
533535
});
534536

535537
test(`${permission} key: matches position contain indices`, async () => {

tests/index.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,29 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
292292
expect(index).toHaveProperty("primaryKey", "newPrimaryKey");
293293
});
294294

295+
test(`${permission} key: rename index using update method`, async () => {
296+
const client = await getClient(permission);
297+
const originalUid = indexNoPk.uid;
298+
const newUid = "renamed_index";
299+
300+
await client.createIndex(originalUid).waitTask();
301+
await client
302+
.updateIndex(originalUid, {
303+
indexUid: newUid,
304+
})
305+
.waitTask();
306+
307+
// Verify the old index no longer exists
308+
await expect(client.getIndex(originalUid)).rejects.toHaveProperty(
309+
"cause.code",
310+
ErrorStatusCode.INDEX_NOT_FOUND,
311+
);
312+
313+
// Verify the new index exists
314+
const index = await client.getIndex(newUid);
315+
expect(index).toHaveProperty("uid", newUid);
316+
});
317+
295318
test(`${permission} key: delete index`, async () => {
296319
const client = await getClient(permission);
297320
await client.createIndex(indexNoPk.uid).waitTask();

tests/search.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ describe.each([
11961196
expect(response).toHaveProperty("hits", expect.any(Array));
11971197
expect(response).toHaveProperty("query", "prince");
11981198
expect(response.hits[0]).toHaveProperty("_vectors");
1199+
expect(response).toHaveProperty("queryVector", expect.any(Array));
11991200
});
12001201

12011202
test(`${permission} key: search without retrieveVectors`, async () => {
@@ -1206,6 +1207,7 @@ describe.each([
12061207
expect(response).toHaveProperty("hits", expect.any(Array));
12071208
expect(response).toHaveProperty("query", "prince");
12081209
expect(response.hits[0]).not.toHaveProperty("_vectors");
1210+
expect(response).not.toHaveProperty("queryVector");
12091211
});
12101212

12111213
test(`${permission} key: Search with locales`, async () => {

0 commit comments

Comments
 (0)