Skip to content

Commit

Permalink
Merge #1768
Browse files Browse the repository at this point in the history
1768: Changes related to the next Meilisearch release (v1.12.0) r=curquiza a=meili-bot

Related to this issue: meilisearch/integration-guides#307

This PR:
- gathers the changes related to the next Meilisearch release (v1.12.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.12.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.12.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: Strift <[email protected]>
Co-authored-by: Clémentine <[email protected]>
Co-authored-by: Laurent Cazanove <[email protected]>
Co-authored-by: Balazs Barabas <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
6 people authored Dec 23, 2024
2 parents 912465a + 966d534 commit d3593cd
Show file tree
Hide file tree
Showing 20 changed files with 1,267 additions and 77 deletions.
16 changes: 16 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,19 @@ update_localized_attribute_settings_1: |-
];)
reset_localized_attribute_settings_1: |-
client.index('INDEX_NAME').resetLocalizedAttributes()
get_facet_search_settings_1: |-
client.index('INDEX_NAME').getFacetSearch();
update_facet_search_settings_1: |-
client.index('INDEX_NAME').updateFacetSearch(false);
reset_facet_search_settings_1: |-
client.index('INDEX_NAME').resetFacetSearch();
get_prefix_search_settings_1: |-
client.index('INDEX_NAME').getPrefixSearch();
update_prefix_search_settings_1: |-
client.index('INDEX_NAME').updatePrefixSearch('disabled');
reset_prefix_search_settings_1: |-
client.index('INDEX_NAME').resetPrefixSearch();
get_all_batches_1: |-
client.getBatches();
get_batch_1: |-
client.getBatch(BATCH_UID);
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,20 @@ client.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number })
client.index('myIndex').waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Task[]>
```

### Batches <!-- omit in toc -->

#### [Get one batch](https://www.meilisearch.com/docs/reference/api/batches#get-one-batch)

```ts
client.getBatch(uid: number): Promise<Batch>
```

#### [Get all batches](https://www.meilisearch.com/docs/reference/api/batchess#get-batches)

```ts
client.getBatches(parameters: BatchesQuery = {}): Promise<BatchesResults>
```

### Indexes <!-- omit in toc -->

#### [Get all indexes in Index instances](https://www.meilisearch.com/docs/reference/api/indexes#list-all-indexes)
Expand Down Expand Up @@ -981,6 +995,46 @@ client.index('myIndex').updateProximityPrecision(proximityPrecision: ProximityPr
client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>
```

### Facet search settings <!-- omit in toc -->

#### [Get facet search settings](https://www.meilisearch.com/docs/reference/api/settings#get-facet-search-settings)

```ts
client.index('myIndex').getFacetSearch(): Promise<boolean>
```

#### [Update facet search settings](https://www.meilisearch.com/docs/reference/api/settings#update-facet-search-settings)

```ts
client.index('myIndex').updateFacetSearch(enabled: boolean): Promise<EnqueuedTask>
```

#### [Reset facet search settings](https://www.meilisearch.com/docs/reference/api/settings#reset-facet-search-settings)

```ts
client.index('myIndex').resetFacetSearch(): Promise<EnqueuedTask>
```

### Prefix search settings <!-- omit in toc -->

#### [Get prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#get-prefix-search-settings)

```ts
client.index('myIndex').getPrefixSearch(): Promise<PrefixSearch>
```

#### [Update prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#update-prefix-search-settings)

```ts
client.index('myIndex').updatePrefixSearch(prefixSearch: PrefixSearch): Promise<EnqueuedTask>
```

#### [Reset prefix search settings](https://www.meilisearch.com/docs/reference/api/settings#reset-prefix-search-settings)

```ts
client.index('myIndex').resetPrefixSearch(): Promise<EnqueuedTask>
```

### Embedders <!-- omit in toc -->

⚠️ This feature is experimental. Activate the [`vectorStore` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features)
Expand Down
70 changes: 70 additions & 0 deletions src/batch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
Config,
BatchObject,
BatchesQuery,
BatchesResults,
BatchesResultsObject,
} from "./types";
import { HttpRequests, toQueryParams } from "./http-requests";

class Batch {
uid: BatchObject["uid"];
details: BatchObject["details"];
stats: BatchObject["stats"];
startedAt: BatchObject["startedAt"];
finishedAt: BatchObject["finishedAt"];
duration: BatchObject["duration"];
progress: BatchObject["progress"];

constructor(batch: BatchObject) {
this.uid = batch.uid;
this.details = batch.details;
this.stats = batch.stats;
this.startedAt = batch.startedAt;
this.finishedAt = batch.finishedAt;
this.duration = batch.duration;
this.progress = batch.progress;
}
}

class BatchClient {
httpRequest: HttpRequests;

constructor(config: Config) {
this.httpRequest = new HttpRequests(config);
}

/**
* Get one batch
*
* @param uid - Unique identifier of the batch
* @returns
*/
async getBatch(uid: number): Promise<Batch> {
const url = `batches/${uid}`;
const batch = await this.httpRequest.get<BatchObject>(url);
return new Batch(batch);
}

/**
* Get batches
*
* @param parameters - Parameters to browse the batches
* @returns Promise containing all batches
*/
async getBatches(parameters: BatchesQuery = {}): Promise<BatchesResults> {
const url = `batches`;

const batches = await this.httpRequest.get<Promise<BatchesResultsObject>>(
url,
toQueryParams<BatchesQuery>(parameters),
);

return {
...batches,
results: batches.results.map((batch) => new Batch(batch)),
};
}
}

export { BatchClient, Batch };
75 changes: 75 additions & 0 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
SearchSimilarDocumentsParams,
LocalizedAttributes,
UpdateDocumentsByFunctionOptions,
PrefixSearch,
} from "./types";
import { removeUndefinedFromObject } from "./utils";
import { HttpRequests } from "./http-requests";
Expand Down Expand Up @@ -1457,6 +1458,80 @@ class Index<T extends Record<string, any> = Record<string, any>> {

return new EnqueuedTask(task);
}

///
/// FACET SEARCH SETTINGS
///

/**
* Get the facet search settings.
*
* @returns Promise containing object of facet search settings
*/
async getFacetSearch(): Promise<boolean> {
const url = `indexes/${this.uid}/settings/facet-search`;
return await this.httpRequest.get<boolean>(url);
}

/**
* Update the facet search settings.
*
* @param facetSearch - Boolean value
* @returns Promise containing an EnqueuedTask
*/
async updateFacetSearch(facetSearch: boolean): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/facet-search`;
const task = await this.httpRequest.put(url, facetSearch);
return new EnqueuedTask(task);
}

/**
* Reset the facet search settings.
*
* @returns Promise containing an EnqueuedTask
*/
async resetFacetSearch(): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/facet-search`;
const task = await this.httpRequest.delete(url);
return new EnqueuedTask(task);
}

///
/// PREFIX SEARCH SETTINGS
///

/**
* Get the prefix search settings.
*
* @returns Promise containing object of prefix search settings
*/
async getPrefixSearch(): Promise<PrefixSearch> {
const url = `indexes/${this.uid}/settings/prefix-search`;
return await this.httpRequest.get<PrefixSearch>(url);
}

/**
* Update the prefix search settings.
*
* @param prefixSearch - PrefixSearch value
* @returns Promise containing an EnqueuedTask
*/
async updatePrefixSearch(prefixSearch: PrefixSearch): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/prefix-search`;
const task = await this.httpRequest.put(url, prefixSearch);
return new EnqueuedTask(task);
}

/**
* Reset the prefix search settings.
*
* @returns Promise containing an EnqueuedTask
*/
async resetPrefixSearch(): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/prefix-search`;
const task = await this.httpRequest.delete(url);
return new EnqueuedTask(task);
}
}

export { Index };
25 changes: 25 additions & 0 deletions src/meilisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ import {
DeleteTasksQuery,
MultiSearchParams,
FederatedMultiSearchParams,
BatchesResults,
BatchesQuery,
MultiSearchResponseOrSearchResponse,
} from "./types";
import { HttpRequests } from "./http-requests";
import { TaskClient, Task } from "./task";
import { EnqueuedTask } from "./enqueued-task";
import { Batch, BatchClient } from "./batch";

export class MeiliSearch {
config: Config;
httpRequest: HttpRequests;
tasks: TaskClient;
batches: BatchClient;

/**
* Creates new MeiliSearch instance
Expand All @@ -50,6 +54,7 @@ export class MeiliSearch {
this.config = config;
this.httpRequest = new HttpRequests(config);
this.tasks = new TaskClient(config);
this.batches = new BatchClient(config);
}

/**
Expand Down Expand Up @@ -303,6 +308,26 @@ export class MeiliSearch {
return await this.tasks.deleteTasks(parameters);
}

/**
* Get all the batches
*
* @param parameters - Parameters to browse the batches
* @returns Promise returning all batches
*/
async getBatches(parameters: BatchesQuery = {}): Promise<BatchesResults> {
return await this.batches.getBatches(parameters);
}

/**
* Get one batch
*
* @param uid - Batch identifier
* @returns Promise returning a batch
*/
async getBatch(uid: number): Promise<Batch> {
return await this.batches.getBatch(uid);
}

///
/// KEYS
///
Expand Down
2 changes: 2 additions & 0 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Task {
status: TaskObject["status"];
type: TaskObject["type"];
uid: TaskObject["uid"];
batchUid: TaskObject["batchUid"];
canceledBy: TaskObject["canceledBy"];
details: TaskObject["details"];
error: TaskObject["error"];
Expand All @@ -32,6 +33,7 @@ class Task {
this.status = task.status;
this.type = task.type;
this.uid = task.uid;
this.batchUid = task.batchUid;
this.details = task.details;
this.canceledBy = task.canceledBy;
this.error = task.error;
Expand Down
Loading

0 comments on commit d3593cd

Please sign in to comment.