Skip to content

Commit

Permalink
docs: add saveObjects, deleteObjects and partialUpdateObjects to helpers
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3256

Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Jun 26, 2024
1 parent c59288f commit cae6425
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/Api/SearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2927,6 +2927,50 @@ public function replaceAllObjects($indexName, $objects, $batchSize = 1000, $requ
];
}

/**
* 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.
*
* @param string $indexName the `indexName` to replace `objects` in
* @param array $objects the array of `objects` to store in the given Algolia `indexName`
* @param array $requestOptions Request options
*/
public function saveObjects($indexName, $objects)
{
return chunkedBatch($indexName, $objects, 'addObject', false, 1000, $requestOptions);
}

/**
* 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.
*
* @param string $indexName the `indexName` to delete `objectIDs` from
* @param array $objectIDs the `objectIDs` to delete
* @param array $requestOptions Request options
* @param mixed $objects
*/
public function deleteObjects($indexName, $objects)
{
$objects = [];

foreach ($id as $objectIDs) {
$objects[] = ['objectID' => $id];
}

return chunkedBatch($indexName, $objects, 'deleteObjects', false, 1000, $requestOptions);
}

/**
* 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.
*
* @param string $indexName the `indexName` to replace `objects` in
* @param array $objects the array of `objects` to store in the given Algolia `indexName`
* @param bool $createIfNotExists To be provided if non-existing objects are passed, otherwise, the call will fail..
* @param array $requestOptions Request options
*/
public function partialUpdateObjects($indexName, $objects, $createIfNotExists)
{
return chunkedBatch($indexName, $objects, (true == $createIfNotExists) ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate', false, 1000, $requestOptions);
}

/**
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
*
Expand Down

0 comments on commit cae6425

Please sign in to comment.