Skip to content

Commit dfe5be8

Browse files
authored
Merge pull request #1774 from meilisearch/feat/add-tasks-reverse
Add reverse parameter for getTasks
2 parents 5ac68c1 + 38fe56f commit dfe5be8

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/types/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ export type TasksQuery = {
556556
afterFinishedAt?: Date;
557557
limit?: number;
558558
from?: number;
559+
/**
560+
* If true, the tasks are returned in reverse order (requires Meilisearch
561+
* 1.12.0 or later)
562+
*/
563+
reverse?: boolean;
559564
};
560565

561566
export type CancelTasksQuery = Omit<TasksQuery, "limit" | "from"> & {};

tests/__snapshots__/settings.test.ts.snap

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exports[`Test on settings > Admin key: Get default settings of an index 1`] = `
77
"*",
88
],
99
"distinctAttribute": null,
10+
"facetSearch": true,
1011
"faceting": {
1112
"maxValuesPerFacet": 100,
1213
"sortFacetValuesBy": {
@@ -19,6 +20,7 @@ exports[`Test on settings > Admin key: Get default settings of an index 1`] = `
1920
"pagination": {
2021
"maxTotalHits": 1000,
2122
},
23+
"prefixSearch": "indexingTime",
2224
"proximityPrecision": "byWord",
2325
"rankingRules": [
2426
"words",
@@ -55,6 +57,7 @@ exports[`Test on settings > Admin key: Get default settings of empty index with
5557
"*",
5658
],
5759
"distinctAttribute": null,
60+
"facetSearch": true,
5861
"faceting": {
5962
"maxValuesPerFacet": 100,
6063
"sortFacetValuesBy": {
@@ -67,6 +70,7 @@ exports[`Test on settings > Admin key: Get default settings of empty index with
6770
"pagination": {
6871
"maxTotalHits": 1000,
6972
},
73+
"prefixSearch": "indexingTime",
7074
"proximityPrecision": "byWord",
7175
"rankingRules": [
7276
"words",
@@ -103,6 +107,7 @@ exports[`Test on settings > Admin key: Reset embedders settings 1`] = `
103107
"*",
104108
],
105109
"distinctAttribute": null,
110+
"facetSearch": true,
106111
"faceting": {
107112
"maxValuesPerFacet": 100,
108113
"sortFacetValuesBy": {
@@ -115,6 +120,7 @@ exports[`Test on settings > Admin key: Reset embedders settings 1`] = `
115120
"pagination": {
116121
"maxTotalHits": 1000,
117122
},
123+
"prefixSearch": "indexingTime",
118124
"proximityPrecision": "byWord",
119125
"rankingRules": [
120126
"words",
@@ -151,6 +157,7 @@ exports[`Test on settings > Admin key: Reset settings 1`] = `
151157
"*",
152158
],
153159
"distinctAttribute": null,
160+
"facetSearch": true,
154161
"faceting": {
155162
"maxValuesPerFacet": 100,
156163
"sortFacetValuesBy": {
@@ -163,6 +170,7 @@ exports[`Test on settings > Admin key: Reset settings 1`] = `
163170
"pagination": {
164171
"maxTotalHits": 1000,
165172
},
173+
"prefixSearch": "indexingTime",
166174
"proximityPrecision": "byWord",
167175
"rankingRules": [
168176
"words",
@@ -199,6 +207,7 @@ exports[`Test on settings > Admin key: Reset settings of empty index 1`] = `
199207
"*",
200208
],
201209
"distinctAttribute": null,
210+
"facetSearch": true,
202211
"faceting": {
203212
"maxValuesPerFacet": 100,
204213
"sortFacetValuesBy": {
@@ -211,6 +220,7 @@ exports[`Test on settings > Admin key: Reset settings of empty index 1`] = `
211220
"pagination": {
212221
"maxTotalHits": 1000,
213222
},
223+
"prefixSearch": "indexingTime",
214224
"proximityPrecision": "byWord",
215225
"rankingRules": [
216226
"words",
@@ -256,6 +266,7 @@ exports[`Test on settings > Admin key: Update embedders settings 1`] = `
256266
"source": "huggingFace",
257267
},
258268
},
269+
"facetSearch": true,
259270
"faceting": {
260271
"maxValuesPerFacet": 100,
261272
"sortFacetValuesBy": {
@@ -268,6 +279,7 @@ exports[`Test on settings > Admin key: Update embedders settings 1`] = `
268279
"pagination": {
269280
"maxTotalHits": 1000,
270281
},
282+
"prefixSearch": "indexingTime",
271283
"proximityPrecision": "byWord",
272284
"rankingRules": [
273285
"words",
@@ -304,6 +316,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
304316
"*",
305317
],
306318
"distinctAttribute": null,
319+
"facetSearch": true,
307320
"faceting": {
308321
"maxValuesPerFacet": 100,
309322
"sortFacetValuesBy": {
@@ -316,6 +329,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
316329
"pagination": {
317330
"maxTotalHits": 1000,
318331
},
332+
"prefixSearch": "indexingTime",
319333
"proximityPrecision": "byWord",
320334
"rankingRules": [
321335
"words",
@@ -352,6 +366,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
352366
"*",
353367
],
354368
"distinctAttribute": null,
369+
"facetSearch": true,
355370
"faceting": {
356371
"maxValuesPerFacet": 100,
357372
"sortFacetValuesBy": {
@@ -364,6 +379,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
364379
"pagination": {
365380
"maxTotalHits": 1000,
366381
},
382+
"prefixSearch": "indexingTime",
367383
"proximityPrecision": "byWord",
368384
"rankingRules": [
369385
"words",
@@ -403,6 +419,7 @@ exports[`Test on settings > Admin key: Update settings 1`] = `
403419
"title",
404420
],
405421
"distinctAttribute": "title",
422+
"facetSearch": true,
406423
"faceting": {
407424
"maxValuesPerFacet": 50,
408425
"sortFacetValuesBy": {
@@ -421,6 +438,7 @@ exports[`Test on settings > Admin key: Update settings 1`] = `
421438
"pagination": {
422439
"maxTotalHits": 1000,
423440
},
441+
"prefixSearch": "indexingTime",
424442
"proximityPrecision": "byAttribute",
425443
"rankingRules": [
426444
"id:asc",
@@ -469,6 +487,7 @@ exports[`Test on settings > Admin key: Update settings on empty index with prima
469487
"*",
470488
],
471489
"distinctAttribute": "title",
490+
"facetSearch": true,
472491
"faceting": {
473492
"maxValuesPerFacet": 100,
474493
"sortFacetValuesBy": {
@@ -481,6 +500,7 @@ exports[`Test on settings > Admin key: Update settings on empty index with prima
481500
"pagination": {
482501
"maxTotalHits": 1000,
483502
},
503+
"prefixSearch": "indexingTime",
484504
"proximityPrecision": "byWord",
485505
"rankingRules": [
486506
"title:asc",
@@ -515,6 +535,7 @@ exports[`Test on settings > Admin key: Update settings with all null values 1`]
515535
"*",
516536
],
517537
"distinctAttribute": null,
538+
"facetSearch": true,
518539
"faceting": {
519540
"maxValuesPerFacet": 100,
520541
"sortFacetValuesBy": {
@@ -527,6 +548,7 @@ exports[`Test on settings > Admin key: Update settings with all null values 1`]
527548
"pagination": {
528549
"maxTotalHits": 1000,
529550
},
551+
"prefixSearch": "indexingTime",
530552
"proximityPrecision": "byWord",
531553
"rankingRules": [
532554
"words",
@@ -563,6 +585,7 @@ exports[`Test on settings > Master key: Get default settings of an index 1`] = `
563585
"*",
564586
],
565587
"distinctAttribute": null,
588+
"facetSearch": true,
566589
"faceting": {
567590
"maxValuesPerFacet": 100,
568591
"sortFacetValuesBy": {
@@ -575,6 +598,7 @@ exports[`Test on settings > Master key: Get default settings of an index 1`] = `
575598
"pagination": {
576599
"maxTotalHits": 1000,
577600
},
601+
"prefixSearch": "indexingTime",
578602
"proximityPrecision": "byWord",
579603
"rankingRules": [
580604
"words",
@@ -611,6 +635,7 @@ exports[`Test on settings > Master key: Get default settings of empty index with
611635
"*",
612636
],
613637
"distinctAttribute": null,
638+
"facetSearch": true,
614639
"faceting": {
615640
"maxValuesPerFacet": 100,
616641
"sortFacetValuesBy": {
@@ -623,6 +648,7 @@ exports[`Test on settings > Master key: Get default settings of empty index with
623648
"pagination": {
624649
"maxTotalHits": 1000,
625650
},
651+
"prefixSearch": "indexingTime",
626652
"proximityPrecision": "byWord",
627653
"rankingRules": [
628654
"words",
@@ -659,6 +685,7 @@ exports[`Test on settings > Master key: Reset embedders settings 1`] = `
659685
"*",
660686
],
661687
"distinctAttribute": null,
688+
"facetSearch": true,
662689
"faceting": {
663690
"maxValuesPerFacet": 100,
664691
"sortFacetValuesBy": {
@@ -671,6 +698,7 @@ exports[`Test on settings > Master key: Reset embedders settings 1`] = `
671698
"pagination": {
672699
"maxTotalHits": 1000,
673700
},
701+
"prefixSearch": "indexingTime",
674702
"proximityPrecision": "byWord",
675703
"rankingRules": [
676704
"words",
@@ -707,6 +735,7 @@ exports[`Test on settings > Master key: Reset settings 1`] = `
707735
"*",
708736
],
709737
"distinctAttribute": null,
738+
"facetSearch": true,
710739
"faceting": {
711740
"maxValuesPerFacet": 100,
712741
"sortFacetValuesBy": {
@@ -719,6 +748,7 @@ exports[`Test on settings > Master key: Reset settings 1`] = `
719748
"pagination": {
720749
"maxTotalHits": 1000,
721750
},
751+
"prefixSearch": "indexingTime",
722752
"proximityPrecision": "byWord",
723753
"rankingRules": [
724754
"words",
@@ -755,6 +785,7 @@ exports[`Test on settings > Master key: Reset settings of empty index 1`] = `
755785
"*",
756786
],
757787
"distinctAttribute": null,
788+
"facetSearch": true,
758789
"faceting": {
759790
"maxValuesPerFacet": 100,
760791
"sortFacetValuesBy": {
@@ -767,6 +798,7 @@ exports[`Test on settings > Master key: Reset settings of empty index 1`] = `
767798
"pagination": {
768799
"maxTotalHits": 1000,
769800
},
801+
"prefixSearch": "indexingTime",
770802
"proximityPrecision": "byWord",
771803
"rankingRules": [
772804
"words",
@@ -812,6 +844,7 @@ exports[`Test on settings > Master key: Update embedders settings 1`] = `
812844
"source": "huggingFace",
813845
},
814846
},
847+
"facetSearch": true,
815848
"faceting": {
816849
"maxValuesPerFacet": 100,
817850
"sortFacetValuesBy": {
@@ -824,6 +857,7 @@ exports[`Test on settings > Master key: Update embedders settings 1`] = `
824857
"pagination": {
825858
"maxTotalHits": 1000,
826859
},
860+
"prefixSearch": "indexingTime",
827861
"proximityPrecision": "byWord",
828862
"rankingRules": [
829863
"words",
@@ -860,6 +894,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
860894
"*",
861895
],
862896
"distinctAttribute": null,
897+
"facetSearch": true,
863898
"faceting": {
864899
"maxValuesPerFacet": 100,
865900
"sortFacetValuesBy": {
@@ -872,6 +907,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
872907
"pagination": {
873908
"maxTotalHits": 1000,
874909
},
910+
"prefixSearch": "indexingTime",
875911
"proximityPrecision": "byWord",
876912
"rankingRules": [
877913
"words",
@@ -908,6 +944,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
908944
"*",
909945
],
910946
"distinctAttribute": null,
947+
"facetSearch": true,
911948
"faceting": {
912949
"maxValuesPerFacet": 100,
913950
"sortFacetValuesBy": {
@@ -920,6 +957,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
920957
"pagination": {
921958
"maxTotalHits": 1000,
922959
},
960+
"prefixSearch": "indexingTime",
923961
"proximityPrecision": "byWord",
924962
"rankingRules": [
925963
"words",
@@ -959,6 +997,7 @@ exports[`Test on settings > Master key: Update settings 1`] = `
959997
"title",
960998
],
961999
"distinctAttribute": "title",
1000+
"facetSearch": true,
9621001
"faceting": {
9631002
"maxValuesPerFacet": 50,
9641003
"sortFacetValuesBy": {
@@ -977,6 +1016,7 @@ exports[`Test on settings > Master key: Update settings 1`] = `
9771016
"pagination": {
9781017
"maxTotalHits": 1000,
9791018
},
1019+
"prefixSearch": "indexingTime",
9801020
"proximityPrecision": "byAttribute",
9811021
"rankingRules": [
9821022
"id:asc",
@@ -1025,6 +1065,7 @@ exports[`Test on settings > Master key: Update settings on empty index with prim
10251065
"*",
10261066
],
10271067
"distinctAttribute": "title",
1068+
"facetSearch": true,
10281069
"faceting": {
10291070
"maxValuesPerFacet": 100,
10301071
"sortFacetValuesBy": {
@@ -1037,6 +1078,7 @@ exports[`Test on settings > Master key: Update settings on empty index with prim
10371078
"pagination": {
10381079
"maxTotalHits": 1000,
10391080
},
1081+
"prefixSearch": "indexingTime",
10401082
"proximityPrecision": "byWord",
10411083
"rankingRules": [
10421084
"title:asc",
@@ -1071,6 +1113,7 @@ exports[`Test on settings > Master key: Update settings with all null values 1`]
10711113
"*",
10721114
],
10731115
"distinctAttribute": null,
1116+
"facetSearch": true,
10741117
"faceting": {
10751118
"maxValuesPerFacet": 100,
10761119
"sortFacetValuesBy": {
@@ -1083,6 +1126,7 @@ exports[`Test on settings > Master key: Update settings with all null values 1`]
10831126
"pagination": {
10841127
"maxTotalHits": 1000,
10851128
},
1129+
"prefixSearch": "indexingTime",
10861130
"proximityPrecision": "byWord",
10871131
"rankingRules": [
10881132
"words",

tests/task.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,32 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
369369
);
370370
});
371371

372+
test(`${permission} key: Get all tasks in reverse order`, async () => {
373+
const currentTimeStamp = Date.now();
374+
const currentTime = new Date(currentTimeStamp);
375+
376+
const client = await getClient(permission);
377+
const taskA = await client.index(index.uid).addDocuments([{ id: 1 }]);
378+
const taskB = await client.index(index.uid).addDocuments([{ id: 2 }]);
379+
380+
await client.waitForTask(taskA.taskUid);
381+
await client.waitForTask(taskB.taskUid);
382+
383+
const tasks = await client.getTasks({ afterEnqueuedAt: currentTime });
384+
const reversedTasks = await client.getTasks({
385+
afterEnqueuedAt: currentTime,
386+
reverse: true,
387+
});
388+
expect(tasks.results.map((t) => t.uid)).toEqual([
389+
taskB.taskUid,
390+
taskA.taskUid,
391+
]);
392+
expect(reversedTasks.results.map((t) => t.uid)).toEqual([
393+
taskA.taskUid,
394+
taskB.taskUid,
395+
]);
396+
});
397+
372398
// filters error code: INVALID_TASK_TYPES_FILTER
373399
test(`${permission} key: Try to filter on task types with wrong type`, async () => {
374400
const client = await getClient(permission);

0 commit comments

Comments
 (0)