Skip to content

Commit 307c268

Browse files
committed
Move to a options = {} impl in Index#delete_documents method
1 parent 4f7c82f commit 307c268

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

lib/meilisearch/index.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,21 @@ def update_documents_in_batches!(documents, batch_size = 1000, primary_key = nil
155155

156156
# Public: Delete documents from an index
157157
#
158-
# documents_ids - An array with document ids (deprecated, optional)
159-
# filter - A hash containing a filter that should match documents.
160-
# Available ONLY with Meilisearch v1.2 and newer (optional)
158+
# options: A Hash or an Array containing documents_ids or a hash with filter:.
159+
# filter: - A hash containing a filter that should match documents.
160+
# Available ONLY with Meilisearch v1.2 and newer (optional)
161161
#
162162
# Returns a Task object.
163-
def delete_documents(documents_ids = nil, filter: nil)
163+
def delete_documents(options = {})
164164
Utils.version_error_handler(__method__) do
165-
if documents_ids.nil?
166-
http_post "/indexes/#{@uid}/documents/delete", { filter: filter }
165+
if options.is_a?(Hash) && options.key?(:filter)
166+
http_post "/indexes/#{@uid}/documents/delete", options
167167
else
168-
documents_ids = [documents_ids] unless documents_ids.is_a?(Array)
168+
# backwards compatibility:
169+
# expect to be a array or/number/string to send alongside as documents_ids.
170+
options = [options] unless options.is_a?(Array)
169171

170-
http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
172+
http_post "/indexes/#{@uid}/documents/delete-batch", options
171173
end
172174
end
173175
end

spec/meilisearch/index/documents_spec.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,29 +393,20 @@
393393
it 'deletes documents based on filter from index (with delete route)' do
394394
expect do
395395
index.update_filterable_attributes(['objectId'])
396-
task = index.delete_documents(nil, filter: ['objectId > 0'])
396+
task = index.delete_documents(filter: ['objectId > 0'])
397397

398398
client.wait_for_task(task['taskUid'])
399399
end.to(change { index.documents['results'].size }.by(-documents.size))
400400
end
401401

402402
it 'ignores filter even when documents_ids is empty (with delete-batch route)' do
403403
expect do
404-
task = index.delete_documents([], filter: ['objectId > 0'])
404+
task = index.delete_documents(filter: ['objectId > 0'])
405405

406406
client.wait_for_task(task['taskUid'])
407407
end.to(change { index.documents['results'].size }.by(0))
408408
end
409409

410-
it 'deletes documents based on ids even when receive a filter (with delete-batch route)' do
411-
expect do
412-
index.update_filterable_attributes(['objectId'])
413-
task = index.delete_documents([2], filter: ['objectId > 0'])
414-
415-
client.wait_for_task(task['taskUid'])
416-
end.to(change { index.documents['results'].size }.by(-1))
417-
end
418-
419410
it 'deletes one document synchronously from index (with delete-batch route)' do
420411
id = 2
421412
expect do

0 commit comments

Comments
 (0)