Skip to content

Commit 49af835

Browse files
chore: generated code for commit 47dd4bb. [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 47dd4bb commit 49af835

File tree

7 files changed

+260
-7
lines changed

7 files changed

+260
-7
lines changed

clients/algoliasearch-client-go/algolia/search/api_search.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6334,6 +6334,68 @@ public <T> ReplaceAllObjectsResponse replaceAllObjects(String indexName, Iterabl
63346334
return replaceAllObjects(indexName, objects, batchSize, null);
63356335
}
63366336

6337+
/**
6338+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used
6339+
* under the hood, which creates a `batch` requests with at most 1000 objects in it.
6340+
*
6341+
* @param indexName The `indexName` to replace `objects` in.
6342+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
6343+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6344+
* the transporter requestOptions. (optional)
6345+
*/
6346+
public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects, RequestOptions requestOptions) {
6347+
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, false, 1000, requestOptions);
6348+
}
6349+
6350+
/**
6351+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under
6352+
* the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
6353+
*
6354+
* @param indexName The `indexName` to delete `objectIDs` from.
6355+
* @param objectIDs The array of `objectIDs` to delete from the `indexName`.
6356+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6357+
* the transporter requestOptions. (optional)
6358+
*/
6359+
public List<BatchResponse> deleteObjects(String indexName, List<String> objectIDs, RequestOptions requestOptions) {
6360+
List<Map<String, String>> objects = new ArrayList<>();
6361+
6362+
for (String id : objectIDs) {
6363+
Map<String, String> obj = new HashMap<>();
6364+
obj.put("objectID", id);
6365+
objects.add(obj);
6366+
}
6367+
6368+
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, false, 1000, requestOptions);
6369+
}
6370+
6371+
/**
6372+
* Helper: Replaces object content of all the given objects according to their respective
6373+
* `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch`
6374+
* requests with at most 1000 objects in it.
6375+
*
6376+
* @param indexName The `indexName` to update `objects` in.
6377+
* @param objects The array of `objects` to update in the given Algolia `indexName`.
6378+
* @param createIfNotExists To be provided if non-existing objects are passed, otherwise, the call
6379+
* will fail.
6380+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6381+
* the transporter requestOptions. (optional)
6382+
*/
6383+
public <T> List<BatchResponse> partialUpdateObjects(
6384+
String indexName,
6385+
Iterable<T> objects,
6386+
boolean createIfNotExists,
6387+
RequestOptions requestOptions
6388+
) {
6389+
return chunkedBatch(
6390+
indexName,
6391+
objects,
6392+
createIfNotExists ? Action.PARTIAL_UPDATE_OBJECT : Action.PARTIAL_UPDATE_OBJECT_NO_CREATE,
6393+
false,
6394+
1000,
6395+
requestOptions
6396+
);
6397+
}
6398+
63376399
/**
63386400
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
63396401
* untouched. Replace all records in an index without any downtime. See

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/SearchClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import com.algolia.client.transport.RequestOptions
1010
import io.ktor.util.*
1111
import kotlinx.datetime.Clock
1212
import kotlinx.datetime.Instant
13-
import kotlinx.serialization.json.JsonObject
1413
import kotlinx.serialization.json.*
14+
import kotlinx.serialization.json.JsonObject
1515
import kotlin.random.Random
1616
import kotlin.time.Duration
1717
import kotlin.time.Duration.Companion.milliseconds

clients/algoliasearch-client-php/lib/Api/SearchClient.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,50 @@ public function replaceAllObjects($indexName, $objects, $batchSize = 1000, $requ
29272927
];
29282928
}
29292929

2930+
/**
2931+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
2932+
*
2933+
* @param string $indexName the `indexName` to replace `objects` in
2934+
* @param array $objects the array of `objects` to store in the given Algolia `indexName`
2935+
* @param array $requestOptions Request options
2936+
*/
2937+
public function saveObjects($indexName, $objects)
2938+
{
2939+
return chunkedBatch($indexName, $objects, 'addObject', false, 1000, $requestOptions);
2940+
}
2941+
2942+
/**
2943+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
2944+
*
2945+
* @param string $indexName the `indexName` to delete `objectIDs` from
2946+
* @param array $objectIDs the `objectIDs` to delete
2947+
* @param array $requestOptions Request options
2948+
* @param mixed $objects
2949+
*/
2950+
public function deleteObjects($indexName, $objects)
2951+
{
2952+
$objects = [];
2953+
2954+
foreach ($id as $objectIDs) {
2955+
$objects[] = ['objectID' => $id];
2956+
}
2957+
2958+
return chunkedBatch($indexName, $objects, 'deleteObjects', false, 1000, $requestOptions);
2959+
}
2960+
2961+
/**
2962+
* Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
2963+
*
2964+
* @param string $indexName the `indexName` to replace `objects` in
2965+
* @param array $objects the array of `objects` to store in the given Algolia `indexName`
2966+
* @param bool $createIfNotExists To be provided if non-existing objects are passed, otherwise, the call will fail..
2967+
* @param array $requestOptions Request options
2968+
*/
2969+
public function partialUpdateObjects($indexName, $objects, $createIfNotExists)
2970+
{
2971+
return chunkedBatch($indexName, $objects, (true == $createIfNotExists) ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate', false, 1000, $requestOptions);
2972+
}
2973+
29302974
/**
29312975
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
29322976
*

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,54 @@ def create_temporary_name(self, index_name: str) -> str:
443443
"""
444444
return "{}_tmp_{}".format(index_name, randint(1000000, 9999999))
445445

446+
async def save_objects(
447+
self,
448+
index_name: str,
449+
objects: List[Dict[str, Any]],
450+
) -> List[BatchResponse]:
451+
"""
452+
Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
453+
"""
454+
return await self.chunked_batch(
455+
index_name=index_name, objects=objects, action=Action.ADDOBJECT
456+
)
457+
458+
async def delete_objects(
459+
self,
460+
index_name: str,
461+
object_ids: List[str],
462+
) -> List[BatchResponse]:
463+
"""
464+
Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
465+
"""
466+
return await self.chunked_batch(
467+
index_name=index_name,
468+
objects=[{"objectID": id} for id in object_ids],
469+
action=Action.DELETEOBJECT,
470+
)
471+
472+
async def partial_update_objects(
473+
self,
474+
index_name: str,
475+
objects: List[Dict[str, Any]],
476+
create_if_not_exists: Optional[bool] = False,
477+
) -> List[BatchResponse]:
478+
"""
479+
Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
480+
"""
481+
return await self.chunked_batch(
482+
index_name=index_name,
483+
objects=objects,
484+
action=Action.PARTIALUPDATEOBJECT
485+
and create_if_not_exists
486+
or Action.PARTIALUPDATEOBJECTNOCREATE,
487+
)
488+
446489
async def chunked_batch(
447490
self,
448491
index_name: str,
449492
objects: List[Dict[str, Any]],
450-
action: Action = "addObject",
493+
action: Action = Action.ADDOBJECT,
451494
wait_for_tasks: bool = False,
452495
batch_size: int = 1000,
453496
request_options: Optional[Union[dict, RequestOptions]] = None,

clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,64 @@ def get_secured_api_key_remaining_validity(secured_api_key)
31783178
valid_until - now
31793179
end
31803180

3181+
# Helper: Saves the given array of objects in the given index. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
3182+
#
3183+
# @param index_name [String]: The `index_name` to save `objects` in.
3184+
# @param objects [Array]: The array of `objects` to store in the given Algolia `indexName`.
3185+
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3186+
#
3187+
# @return [BatchResponse]
3188+
#
3189+
def save_objects(index_name, objects, request_options = {})
3190+
chunked_batch(
3191+
index_name,
3192+
objects,
3193+
Search::Action::ADD_OBJECT,
3194+
false,
3195+
1000,
3196+
request_options
3197+
)
3198+
end
3199+
3200+
# Helper: Deletes every records for the given objectIDs. The `chunked_batch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
3201+
#
3202+
# @param index_name [String]: The `index_name` to delete `object_ids` from.
3203+
# @param object_ids [Array]: The object_ids to delete.
3204+
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3205+
#
3206+
# @return [BatchResponse]
3207+
#
3208+
def delete_objects(index_name, object_ids, request_options = {})
3209+
chunked_batch(
3210+
index_name,
3211+
object_ids.map { |id| { "objectID" => id } },
3212+
Search::Action::DELETE_OBJECT,
3213+
false,
3214+
1000,
3215+
request_options
3216+
)
3217+
end
3218+
3219+
# Helper: Replaces object content of all the given objects according to their respective `object_id` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
3220+
#
3221+
# @param index_name [String]: The `index_name` to delete `object_ids` from.
3222+
# @param objects [Array]: The objects to partially update.
3223+
# @param create_if_not_exists [Boolean]: To be provided if non-existing objects are passed, otherwise, the call will fail.
3224+
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
3225+
#
3226+
# @return [BatchResponse]
3227+
#
3228+
def partial_update_objects(index_name, objects, create_if_not_exists, request_options = {})
3229+
chunked_batch(
3230+
index_name,
3231+
objects,
3232+
create_if_not_exists ? Search::Action::PARTIAL_UPDATE_OBJECT : Search::Action::PARTIAL_UPDATE_OBJECT_NO_CREATE,
3233+
false,
3234+
1000,
3235+
request_options
3236+
)
3237+
end
3238+
31813239
# Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
31823240
#
31833241
# @param index_name [String] the `index_name` where the operation will be performed.

clients/algoliasearch-client-scala/src/main/scala/algoliasearch/extension/package.scala

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ package object extension {
244244
responses
245245
}
246246

247-
/** Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
247+
/** Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood,
248+
* which creates a `batch` requests with at most 1000 objects in it.
248249
*
249250
* @param indexName
250251
* The index in which to perform the request.
@@ -263,7 +264,8 @@ package object extension {
263264
chunkedBatch(indexName, objects, Action.AddObject, false, 1000, requestOptions)
264265
}
265266

266-
/** Helper: Deletes every objects for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
267+
/** Helper: Deletes every objects for the given objectIDs. The `chunkedBatch` helper is used under the hood, which
268+
* creates a `batch` requests with at most 1000 objectIDs in it.
267269
*
268270
* @param indexName
269271
* The index in which to perform the request.
@@ -279,10 +281,18 @@ package object extension {
279281
objectIDs: Seq[String],
280282
requestOptions: Option[RequestOptions] = None
281283
)(implicit ec: ExecutionContext): Future[Seq[BatchResponse]] = {
282-
chunkedBatch(indexName, objectIDs.map(id => new { val objectID: String = id }), Action.DeleteObject, false, 1000, requestOptions)
284+
chunkedBatch(
285+
indexName,
286+
objectIDs.map(id => new { val objectID: String = id }),
287+
Action.DeleteObject,
288+
false,
289+
1000,
290+
requestOptions
291+
)
283292
}
284293

285-
/** Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
294+
/** Helper: Replaces object content of all the given objects according to their respective `objectID` field. The
295+
* `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
286296
*
287297
* @param indexName
288298
* The index in which to perform the request.
@@ -301,7 +311,14 @@ package object extension {
301311
createIfNotExists: Boolean,
302312
requestOptions: Option[RequestOptions] = None
303313
)(implicit ec: ExecutionContext): Future[Seq[BatchResponse]] = {
304-
chunkedBatch(indexName, objects, if (createIfNotExists) Action.PartialUpdateObject else Action.PartialUpdateObjectNoCreate, false, 1000, requestOptions)
314+
chunkedBatch(
315+
indexName,
316+
objects,
317+
if (createIfNotExists) Action.PartialUpdateObject else Action.PartialUpdateObjectNoCreate,
318+
false,
319+
1000,
320+
requestOptions
321+
)
305322
}
306323

307324
/** Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are untouched.

0 commit comments

Comments
 (0)