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 <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Jun 26, 2024
1 parent ebb6609 commit dc8615f
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions lib/algolia/api/search_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3178,6 +3178,64 @@ def get_secured_api_key_remaining_validity(secured_api_key)
valid_until - now
end

# 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.
#
# @param index_name [String]: The `index_name` to save `objects` in.
# @param objects [Array]: The array of `objects` to store in the given Algolia `indexName`.
# @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)
#
# @return [BatchResponse]
#
def save_objects(index_name, objects, request_options = {})
chunked_batch(
index_name,
objects,
Search::Action::ADD_OBJECT,
false,
1000,
request_options
)
end

# 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.
#
# @param index_name [String]: The `index_name` to delete `object_ids` from.
# @param object_ids [Array]: The object_ids to delete.
# @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)
#
# @return [BatchResponse]
#
def delete_objects(index_name, object_ids, request_options = {})
chunked_batch(
index_name,
object_ids.map { |id| { "objectID" => id } },
Search::Action::DELETE_OBJECT,
false,
1000,
request_options
)
end

# 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.
#
# @param index_name [String]: The `index_name` to delete `object_ids` from.
# @param objects [Array]: The objects to partially update.
# @param create_if_not_exists [Boolean]: To be provided if non-existing objects are passed, otherwise, the call will fail.
# @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)
#
# @return [BatchResponse]
#
def partial_update_objects(index_name, objects, create_if_not_exists, request_options = {})
chunked_batch(
index_name,
objects,
create_if_not_exists ? Search::Action::PARTIAL_UPDATE_OBJECT : Search::Action::PARTIAL_UPDATE_OBJECT_NO_CREATE,
false,
1000,
request_options
)
end

# Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
#
# @param index_name [String] the `index_name` where the operation will be performed.
Expand Down

0 comments on commit dc8615f

Please sign in to comment.