Skip to content

Commit

Permalink
feat(clients): add optionnal scopes to replaceAllObjects [skip-bc] (g…
Browse files Browse the repository at this point in the history
…enerated)

algolia/api-clients-automation#4296

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Pierre Millot <[email protected]>
  • Loading branch information
algolia-bot and millotp committed Jan 7, 2025
1 parent aaf5e87 commit e297b32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/client-search/model/clientMethodProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { OperationIndexParams } from '../model/operationIndexParams';

import type { Rule } from '../model/rule';

import type { ScopeType } from '../model/scopeType';
import type { SearchDictionaryEntriesParams } from '../model/searchDictionaryEntriesParams';

import type { SearchForFacetValuesRequest } from '../model/searchForFacetValuesRequest';
Expand Down Expand Up @@ -870,4 +871,9 @@ export type ReplaceAllObjectsOptions = {
* The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
*/
batchSize?: number;

/**
* The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
*/
scopes?: Array<ScopeType>;
};
11 changes: 8 additions & 3 deletions packages/client-search/src/searchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,23 +633,28 @@ export function createSearchClient({
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
* @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
* @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
* @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch`, `operationIndex` and `getTask` method and merged with the transporter requestOptions.
*/
async replaceAllObjects(
{ indexName, objects, batchSize }: ReplaceAllObjectsOptions,
{ indexName, objects, batchSize, scopes }: ReplaceAllObjectsOptions,
requestOptions?: RequestOptions,
): Promise<ReplaceAllObjectsResponse> {
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;

if (scopes === undefined) {
scopes = ['settings', 'rules', 'synonyms'];
}

try {
let copyOperationResponse = await this.operationIndex(
{
indexName,
operationIndexParams: {
operation: 'copy',
destination: tmpIndexName,
scope: ['settings', 'rules', 'synonyms'],
scope: scopes,
},
},
requestOptions,
Expand All @@ -671,7 +676,7 @@ export function createSearchClient({
operationIndexParams: {
operation: 'copy',
destination: tmpIndexName,
scope: ['settings', 'rules', 'synonyms'],
scope: scopes,
},
},
requestOptions,
Expand Down

0 comments on commit e297b32

Please sign in to comment.