Skip to content

Commit ee63ac8

Browse files
authored
Merge branch 'main' into remove-cross-fetch
2 parents 899d2a7 + bb4f53e commit ee63ac8

13 files changed

+576
-31
lines changed

.code-samples.meilisearch.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,3 +773,29 @@ distinct_attribute_guide_filterable_1: |-
773773
client.index('products').updateFilterableAttributes(['product_id', 'sku', 'url'])
774774
distinct_attribute_guide_distinct_parameter_1: |-
775775
client.index('products').search('white shirt', { distinct: 'sku' })
776+
multi_search_federated_1: |-
777+
client.multiSearch({
778+
federation: {},
779+
queries: [
780+
{
781+
indexUid: 'movies',
782+
q: 'batman',
783+
limit: 5,
784+
},
785+
{
786+
indexUid: 'comics',
787+
q: 'batman',
788+
limit: 5,
789+
},
790+
]
791+
})
792+
search_parameter_reference_locales_1: |-
793+
client.index('INDEX_NAME').search('進撃の巨人', { locales: ['jpn'] })
794+
get_localized_attribute_settings_1: |-
795+
client.index('INDEX_NAME').getLocalizedAttributes()
796+
update_localized_attribute_settings_1: |-
797+
client.index('INDEX_NAME').updateLocalizedAttributes([
798+
{ attributePatterns: ['jpn'], locales: ['*_ja'] },
799+
];)
800+
reset_localized_attribute_settings_1: |-
801+
client.index('INDEX_NAME').resetLocalizedAttributes()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "meilisearch",
3-
"version": "0.41.0",
3+
"version": "0.42.0",
44
"description": "The Meilisearch JS client for Node.js and the browser.",
55
"keywords": [
66
"meilisearch",

src/clients/client.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Copyright: 2019, MeiliSearch
66
*/
77

8-
'use strict';
9-
108
import { Index } from '../indexes';
119
import {
1210
KeyCreation,
@@ -34,6 +32,8 @@ import {
3432
DeleteTasksQuery,
3533
MultiSearchParams,
3634
MultiSearchResponse,
35+
SearchResponse,
36+
FederatedMultiSearchParams,
3737
} from '../types';
3838
import { HttpRequests } from '../http-requests';
3939
import { TaskClient, Task } from '../task';
@@ -216,10 +216,18 @@ class Client {
216216
* @param config - Additional request configuration options
217217
* @returns Promise containing the search responses
218218
*/
219-
async multiSearch<T extends Record<string, any> = Record<string, any>>(
220-
queries?: MultiSearchParams,
219+
multiSearch<T extends Record<string, unknown> = Record<string, any>>(
220+
queries: MultiSearchParams,
221+
config?: Partial<Request>,
222+
): Promise<MultiSearchResponse<T>>;
223+
multiSearch<T extends Record<string, unknown> = Record<string, any>>(
224+
queries: FederatedMultiSearchParams,
225+
config?: Partial<Request>,
226+
): Promise<SearchResponse<T>>;
227+
async multiSearch<T extends Record<string, unknown> = Record<string, any>>(
228+
queries: MultiSearchParams | FederatedMultiSearchParams,
221229
config?: Partial<Request>,
222-
): Promise<MultiSearchResponse<T>> {
230+
): Promise<MultiSearchResponse<T> | SearchResponse<T>> {
223231
const url = `multi-search`;
224232

225233
return await this.httpRequest.post(url, queries, undefined, config);

src/indexes.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import {
5454
Embedders,
5555
SearchCutoffMs,
5656
SearchSimilarDocumentsParams,
57+
LocalizedAttributes,
58+
UpdateDocumentsByFunctionOptions,
5759
} from './types';
5860
import { removeUndefinedFromObject } from './utils';
5961
import { HttpRequests } from './http-requests';
@@ -629,6 +631,27 @@ class Index<T extends Record<string, any> = Record<string, any>> {
629631
return task;
630632
}
631633

634+
/**
635+
* This is an EXPERIMENTAL feature, which may break without a major version.
636+
* It's available after Meilisearch v1.10.
637+
*
638+
* More info about the feature:
639+
* https://github.com/orgs/meilisearch/discussions/762 More info about
640+
* experimental features in general:
641+
* https://www.meilisearch.com/docs/reference/api/experimental-features
642+
*
643+
* @param options - Object containing the function string and related options
644+
* @returns Promise containing an EnqueuedTask
645+
*/
646+
async updateDocumentsByFunction(
647+
options: UpdateDocumentsByFunctionOptions,
648+
): Promise<EnqueuedTask> {
649+
const url = `indexes/${this.uid}/documents/edit`;
650+
const task = await this.httpRequest.post(url, options);
651+
652+
return new EnqueuedTask(task);
653+
}
654+
632655
///
633656
/// SETTINGS
634657
///
@@ -1393,6 +1416,47 @@ class Index<T extends Record<string, any> = Record<string, any>> {
13931416

13941417
return new EnqueuedTask(task);
13951418
}
1419+
1420+
///
1421+
/// LOCALIZED ATTRIBUTES SETTINGS
1422+
///
1423+
1424+
/**
1425+
* Get the localized attributes settings.
1426+
*
1427+
* @returns Promise containing object of localized attributes settings
1428+
*/
1429+
async getLocalizedAttributes(): Promise<LocalizedAttributes> {
1430+
const url = `indexes/${this.uid}/settings/localized-attributes`;
1431+
return await this.httpRequest.get<LocalizedAttributes>(url);
1432+
}
1433+
1434+
/**
1435+
* Update the localized attributes settings.
1436+
*
1437+
* @param localizedAttributes - Localized attributes object
1438+
* @returns Promise containing an EnqueuedTask
1439+
*/
1440+
async updateLocalizedAttributes(
1441+
localizedAttributes: LocalizedAttributes,
1442+
): Promise<EnqueuedTask> {
1443+
const url = `indexes/${this.uid}/settings/localized-attributes`;
1444+
const task = await this.httpRequest.put(url, localizedAttributes);
1445+
1446+
return new EnqueuedTask(task);
1447+
}
1448+
1449+
/**
1450+
* Reset the localized attributes settings.
1451+
*
1452+
* @returns Promise containing an EnqueuedTask
1453+
*/
1454+
async resetLocalizedAttributes(): Promise<EnqueuedTask> {
1455+
const url = `indexes/${this.uid}/settings/localized-attributes`;
1456+
const task = await this.httpRequest.delete(url);
1457+
1458+
return new EnqueuedTask(task);
1459+
}
13961460
}
13971461

13981462
export { Index };

src/package-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const PACKAGE_VERSION = '0.41.0';
1+
export const PACKAGE_VERSION = '0.42.0';

src/types/types.ts

Lines changed: 54 additions & 14 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,13 +156,24 @@ export type SearchRequestGET = Pagination &
152156
rankingScoreThreshold?: number;
153157
distinct?: string;
154158
retrieveVectors?: boolean;
159+
locales?: Locale[];
155160
};
156161

162+
export type FederationOptions = { weight: number };
163+
export type MultiSearchFederation = { limit?: number; offset?: number };
164+
157165
export type MultiSearchQuery = SearchParams & { indexUid: string };
166+
export type MultiSearchQueryWithFederation = MultiSearchQuery & {
167+
federationOptions?: FederationOptions;
168+
};
158169

159170
export type MultiSearchParams = {
160171
queries: MultiSearchQuery[];
161172
};
173+
export type FederatedMultiSearchParams = {
174+
federation: MultiSearchFederation;
175+
queries: MultiSearchQueryWithFederation[];
176+
};
162177

163178
export type CategoriesDistribution = {
164179
[category: string]: number;
@@ -170,13 +185,6 @@ export type MatchesPosition<T> = Partial<
170185
Record<keyof T, Array<{ start: number; length: number }>>
171186
>;
172187

173-
export type Hit<T = Record<string, any>> = T & {
174-
_formatted?: Partial<T>;
175-
_matchesPosition?: MatchesPosition<T>;
176-
_rankingScore?: number;
177-
_rankingScoreDetails?: RankingScoreDetails;
178-
};
179-
180188
export type RankingScoreDetails = {
181189
words?: {
182190
order: number;
@@ -208,6 +216,20 @@ export type RankingScoreDetails = {
208216
[key: string]: Record<string, any> | undefined;
209217
};
210218

219+
export type FederationDetails = {
220+
indexUid: string;
221+
queriesPosition: number;
222+
weightedRankingScore: number;
223+
};
224+
225+
export type Hit<T = Record<string, any>> = T & {
226+
_formatted?: Partial<T>;
227+
_matchesPosition?: MatchesPosition<T>;
228+
_rankingScore?: number;
229+
_rankingScoreDetails?: RankingScoreDetails;
230+
_federation?: FederationDetails;
231+
};
232+
211233
export type Hits<T = Record<string, any>> = Array<Hit<T>>;
212234

213235
export type FacetStat = { min: number; max: number };
@@ -326,6 +348,12 @@ export type DocumentsDeletionQuery = {
326348

327349
export type DocumentsIds = string[] | number[];
328350

351+
export type UpdateDocumentsByFunctionOptions = {
352+
function: string;
353+
filter?: string | string[];
354+
context?: Record<string, any>;
355+
};
356+
329357
/*
330358
** Settings
331359
*/
@@ -366,6 +394,7 @@ export type OpenAiEmbedder = {
366394
documentTemplate?: string;
367395
dimensions?: number;
368396
distribution?: Distribution;
397+
url?: string;
369398
};
370399

371400
export type HuggingFaceEmbedder = {
@@ -388,12 +417,10 @@ export type RestEmbedder = {
388417
apiKey?: string;
389418
dimensions?: number;
390419
documentTemplate?: string;
391-
inputField?: string[] | null;
392-
inputType?: 'text' | 'textArray';
393-
query?: Record<string, any> | null;
394-
pathToEmbeddings?: string[] | null;
395-
embeddingObject?: string[] | null;
396420
distribution?: Distribution;
421+
request: Record<string, any>;
422+
response: Record<string, any>;
423+
headers?: Record<string, string>;
397424
};
398425

399426
export type OllamaEmbedder = {
@@ -403,6 +430,7 @@ export type OllamaEmbedder = {
403430
model?: string;
404431
documentTemplate?: string;
405432
distribution?: Distribution;
433+
dimensions?: number;
406434
};
407435

408436
export type Embedder =
@@ -428,6 +456,13 @@ export type PaginationSettings = {
428456

429457
export type SearchCutoffMs = number | null;
430458

459+
export type LocalizedAttribute = {
460+
attributePatterns: string[];
461+
locales: Locale[];
462+
};
463+
464+
export type LocalizedAttributes = LocalizedAttribute[] | null;
465+
431466
export type Settings = {
432467
filterableAttributes?: FilterableAttributes;
433468
distinctAttribute?: DistinctAttribute;
@@ -446,6 +481,7 @@ export type Settings = {
446481
proximityPrecision?: ProximityPrecision;
447482
embedders?: Embedders;
448483
searchCutoffMs?: SearchCutoffMs;
484+
localizedAttributes?: LocalizedAttributes;
449485
};
450486

451487
/*
@@ -677,9 +713,9 @@ export interface FetchError extends Error {
677713

678714
export type MeiliSearchErrorResponse = {
679715
message: string;
680-
// @TODO: Could be typed, but will it be kept updated? https://www.meilisearch.com/docs/reference/errors/error_codes
716+
// https://www.meilisearch.com/docs/reference/errors/error_codes
681717
code: string;
682-
// @TODO: Could be typed https://www.meilisearch.com/docs/reference/errors/overview#errors
718+
// https://www.meilisearch.com/docs/reference/errors/overview#errors
683719
type: string;
684720
link: string;
685721
};
@@ -992,6 +1028,10 @@ export const ErrorStatusCode = {
9921028
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */
9931029
INVALID_SETTINGS_SEARCH_CUTOFF_MS: 'invalid_settings_search_cutoff_ms',
9941030

1031+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_settings_search_cutoff_ms */
1032+
INVALID_SETTINGS_LOCALIZED_ATTRIBUTES:
1033+
'invalid_settings_localized_attributes',
1034+
9951035
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_task_before_enqueued_at */
9961036
INVALID_TASK_BEFORE_ENQUEUED_AT: 'invalid_task_before_enqueued_at',
9971037

0 commit comments

Comments
 (0)