Skip to content

Commit a2d46d5

Browse files
authored
Merge pull request #1693 from flevi29/feature-lang-settings-search-params
Add language settings & search parameter
2 parents a0a27cc + 74b48ab commit a2d46d5

File tree

6 files changed

+313
-2
lines changed

6 files changed

+313
-2
lines changed

src/indexes.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
Embedders,
5555
SearchCutoffMs,
5656
SearchSimilarDocumentsParams,
57+
LocalizedAttributes,
5758
} from './types';
5859
import { removeUndefinedFromObject } from './utils';
5960
import { HttpRequests } from './http-requests';
@@ -1393,6 +1394,47 @@ class Index<T extends Record<string, any> = Record<string, any>> {
13931394

13941395
return new EnqueuedTask(task);
13951396
}
1397+
1398+
///
1399+
/// LOCALIZED ATTRIBUTES SETTINGS
1400+
///
1401+
1402+
/**
1403+
* Get the localized attributes settings.
1404+
*
1405+
* @returns Promise containing object of localized attributes settings
1406+
*/
1407+
async getLocalizedAttributes(): Promise<LocalizedAttributes> {
1408+
const url = `indexes/${this.uid}/settings/localized-attributes`;
1409+
return await this.httpRequest.get<LocalizedAttributes>(url);
1410+
}
1411+
1412+
/**
1413+
* Update the localized attributes settings.
1414+
*
1415+
* @param localizedAttributes - Localized attributes object
1416+
* @returns Promise containing an EnqueuedTask
1417+
*/
1418+
async updateLocalizedAttributes(
1419+
localizedAttributes: LocalizedAttributes,
1420+
): Promise<EnqueuedTask> {
1421+
const url = `indexes/${this.uid}/settings/localized-attributes`;
1422+
const task = await this.httpRequest.put(url, localizedAttributes);
1423+
1424+
return new EnqueuedTask(task);
1425+
}
1426+
1427+
/**
1428+
* Reset the localized attributes settings.
1429+
*
1430+
* @returns Promise containing an EnqueuedTask
1431+
*/
1432+
async resetLocalizedAttributes(): Promise<EnqueuedTask> {
1433+
const url = `indexes/${this.uid}/settings/localized-attributes`;
1434+
const task = await this.httpRequest.delete(url);
1435+
1436+
return new EnqueuedTask(task);
1437+
}
13961438
}
13971439

13981440
export { Index };

src/types/types.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export type HybridSearch = {
108108
semanticRatio?: number;
109109
};
110110

111+
// https://www.meilisearch.com/docs/reference/api/settings#localized-attributes
112+
export type Locale = string;
113+
111114
export type SearchParams = Query &
112115
Pagination &
113116
Highlight &
@@ -130,6 +133,7 @@ export type SearchParams = Query &
130133
hybrid?: HybridSearch;
131134
distinct?: string;
132135
retrieveVectors?: boolean;
136+
locales?: Locale[];
133137
};
134138

135139
// Search parameters for searches made with the GET method
@@ -152,6 +156,7 @@ export type SearchRequestGET = Pagination &
152156
rankingScoreThreshold?: number;
153157
distinct?: string;
154158
retrieveVectors?: boolean;
159+
locales?: Locale[];
155160
};
156161

157162
export type MultiSearchQuery = SearchParams & { indexUid: string };
@@ -428,6 +433,13 @@ export type PaginationSettings = {
428433

429434
export type SearchCutoffMs = number | null;
430435

436+
export type LocalizedAttribute = {
437+
attributePatterns: string[];
438+
locales: Locale[];
439+
};
440+
441+
export type LocalizedAttributes = LocalizedAttribute[] | null;
442+
431443
export type Settings = {
432444
filterableAttributes?: FilterableAttributes;
433445
distinctAttribute?: DistinctAttribute;
@@ -446,6 +458,7 @@ export type Settings = {
446458
proximityPrecision?: ProximityPrecision;
447459
embedders?: Embedders;
448460
searchCutoffMs?: SearchCutoffMs;
461+
localizedAttributes?: LocalizedAttributes;
449462
};
450463

451464
/*
@@ -677,9 +690,9 @@ export interface FetchError extends Error {
677690

678691
export type MeiliSearchErrorResponse = {
679692
message: string;
680-
// @TODO: Could be typed, but will it be kept updated? https://www.meilisearch.com/docs/reference/errors/error_codes
693+
// https://www.meilisearch.com/docs/reference/errors/error_codes
681694
code: string;
682-
// @TODO: Could be typed https://www.meilisearch.com/docs/reference/errors/overview#errors
695+
// https://www.meilisearch.com/docs/reference/errors/overview#errors
683696
type: string;
684697
link: string;
685698
};
@@ -992,6 +1005,10 @@ export const ErrorStatusCode = {
9921005
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */
9931006
INVALID_SETTINGS_SEARCH_CUTOFF_MS: 'invalid_settings_search_cutoff_ms',
9941007

1008+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */
1009+
INVALID_SETTINGS_LOCALIZED_ATTRIBUTES:
1010+
'invalid_settings_localized_attributes',
1011+
9951012
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_before_enqueued_at */
9961013
INVALID_TASK_BEFORE_ENQUEUED_AT: 'invalid_task_before_enqueued_at',
9971014

tests/__snapshots__/settings.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports[`Test on settings Admin key: Get default settings of an index 1`] = `
1414
},
1515
},
1616
"filterableAttributes": [],
17+
"localizedAttributes": null,
1718
"nonSeparatorTokens": [],
1819
"pagination": {
1920
"maxTotalHits": 1000,
@@ -61,6 +62,7 @@ exports[`Test on settings Admin key: Get default settings of empty index with pr
6162
},
6263
},
6364
"filterableAttributes": [],
65+
"localizedAttributes": null,
6466
"nonSeparatorTokens": [],
6567
"pagination": {
6668
"maxTotalHits": 1000,
@@ -108,6 +110,7 @@ exports[`Test on settings Admin key: Reset embedders settings 1`] = `
108110
},
109111
},
110112
"filterableAttributes": [],
113+
"localizedAttributes": null,
111114
"nonSeparatorTokens": [],
112115
"pagination": {
113116
"maxTotalHits": 1000,
@@ -155,6 +158,7 @@ exports[`Test on settings Admin key: Reset settings 1`] = `
155158
},
156159
},
157160
"filterableAttributes": [],
161+
"localizedAttributes": null,
158162
"nonSeparatorTokens": [],
159163
"pagination": {
160164
"maxTotalHits": 1000,
@@ -202,6 +206,7 @@ exports[`Test on settings Admin key: Reset settings of empty index 1`] = `
202206
},
203207
},
204208
"filterableAttributes": [],
209+
"localizedAttributes": null,
205210
"nonSeparatorTokens": [],
206211
"pagination": {
207212
"maxTotalHits": 1000,
@@ -257,6 +262,7 @@ exports[`Test on settings Admin key: Update embedders settings 1`] = `
257262
},
258263
},
259264
"filterableAttributes": [],
265+
"localizedAttributes": null,
260266
"nonSeparatorTokens": [],
261267
"pagination": {
262268
"maxTotalHits": 1000,
@@ -304,6 +310,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp
304310
},
305311
},
306312
"filterableAttributes": [],
313+
"localizedAttributes": null,
307314
"nonSeparatorTokens": [],
308315
"pagination": {
309316
"maxTotalHits": 1000,
@@ -351,6 +358,7 @@ exports[`Test on settings Admin key: Update searchableAttributes settings on emp
351358
},
352359
},
353360
"filterableAttributes": [],
361+
"localizedAttributes": null,
354362
"nonSeparatorTokens": [],
355363
"pagination": {
356364
"maxTotalHits": 1000,
@@ -403,6 +411,7 @@ exports[`Test on settings Admin key: Update settings 1`] = `
403411
"filterableAttributes": [
404412
"title",
405413
],
414+
"localizedAttributes": null,
406415
"nonSeparatorTokens": [
407416
"&sep",
408417
"/",
@@ -466,6 +475,7 @@ exports[`Test on settings Admin key: Update settings on empty index with primary
466475
},
467476
},
468477
"filterableAttributes": [],
478+
"localizedAttributes": null,
469479
"nonSeparatorTokens": [],
470480
"pagination": {
471481
"maxTotalHits": 1000,
@@ -511,6 +521,7 @@ exports[`Test on settings Admin key: Update settings with all null values 1`] =
511521
},
512522
},
513523
"filterableAttributes": [],
524+
"localizedAttributes": null,
514525
"nonSeparatorTokens": [],
515526
"pagination": {
516527
"maxTotalHits": 1000,
@@ -558,6 +569,7 @@ exports[`Test on settings Master key: Get default settings of an index 1`] = `
558569
},
559570
},
560571
"filterableAttributes": [],
572+
"localizedAttributes": null,
561573
"nonSeparatorTokens": [],
562574
"pagination": {
563575
"maxTotalHits": 1000,
@@ -605,6 +617,7 @@ exports[`Test on settings Master key: Get default settings of empty index with p
605617
},
606618
},
607619
"filterableAttributes": [],
620+
"localizedAttributes": null,
608621
"nonSeparatorTokens": [],
609622
"pagination": {
610623
"maxTotalHits": 1000,
@@ -652,6 +665,7 @@ exports[`Test on settings Master key: Reset embedders settings 1`] = `
652665
},
653666
},
654667
"filterableAttributes": [],
668+
"localizedAttributes": null,
655669
"nonSeparatorTokens": [],
656670
"pagination": {
657671
"maxTotalHits": 1000,
@@ -699,6 +713,7 @@ exports[`Test on settings Master key: Reset settings 1`] = `
699713
},
700714
},
701715
"filterableAttributes": [],
716+
"localizedAttributes": null,
702717
"nonSeparatorTokens": [],
703718
"pagination": {
704719
"maxTotalHits": 1000,
@@ -746,6 +761,7 @@ exports[`Test on settings Master key: Reset settings of empty index 1`] = `
746761
},
747762
},
748763
"filterableAttributes": [],
764+
"localizedAttributes": null,
749765
"nonSeparatorTokens": [],
750766
"pagination": {
751767
"maxTotalHits": 1000,
@@ -801,6 +817,7 @@ exports[`Test on settings Master key: Update embedders settings 1`] = `
801817
},
802818
},
803819
"filterableAttributes": [],
820+
"localizedAttributes": null,
804821
"nonSeparatorTokens": [],
805822
"pagination": {
806823
"maxTotalHits": 1000,
@@ -848,6 +865,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em
848865
},
849866
},
850867
"filterableAttributes": [],
868+
"localizedAttributes": null,
851869
"nonSeparatorTokens": [],
852870
"pagination": {
853871
"maxTotalHits": 1000,
@@ -895,6 +913,7 @@ exports[`Test on settings Master key: Update searchableAttributes settings on em
895913
},
896914
},
897915
"filterableAttributes": [],
916+
"localizedAttributes": null,
898917
"nonSeparatorTokens": [],
899918
"pagination": {
900919
"maxTotalHits": 1000,
@@ -947,6 +966,7 @@ exports[`Test on settings Master key: Update settings 1`] = `
947966
"filterableAttributes": [
948967
"title",
949968
],
969+
"localizedAttributes": null,
950970
"nonSeparatorTokens": [
951971
"&sep",
952972
"/",
@@ -1010,6 +1030,7 @@ exports[`Test on settings Master key: Update settings on empty index with primar
10101030
},
10111031
},
10121032
"filterableAttributes": [],
1033+
"localizedAttributes": null,
10131034
"nonSeparatorTokens": [],
10141035
"pagination": {
10151036
"maxTotalHits": 1000,
@@ -1055,6 +1076,7 @@ exports[`Test on settings Master key: Update settings with all null values 1`] =
10551076
},
10561077
},
10571078
"filterableAttributes": [],
1079+
"localizedAttributes": null,
10581080
"nonSeparatorTokens": [],
10591081
"pagination": {
10601082
"maxTotalHits": 1000,

0 commit comments

Comments
 (0)