Skip to content

Commit c276aa7

Browse files
committed
Support for bulk delete
1 parent d16df37 commit c276aa7

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Tests are also a good place to know how the the library works internally: [spec]
3333

3434
| Typesense Server | typesense-ruby |
3535
|------------------|----------------|
36+
| \>= v0.17.0 | \>= v0.9.0 |
3637
| \>= v0.16.0 | \>= v0.8.0 |
3738
| \>= v0.15.0 | \>= v0.7.0 |
3839
| \>= v0.12.1 | \>= v0.5.0 |

examples/collections_and_documents.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@
258258
}
259259
ap @typesense.collections['companies'].documents.import(documents, action: :update)
260260

261+
## You can also bulk delete documents, using filter_by fields:
262+
ap @typesense.collections['companies'].documents.delete(filter_by: 'num_employees:>100')
263+
261264
##
262265
# Export all documents in a collection in JSON Lines format
263266
# We use JSON Lines format for performance reasons. You can choose to parse selected lines as needed, by splitting on \n.

lib/typesense/documents.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def [](document_id)
6464
@documents[document_id] ||= Document.new(@collection_name, document_id, @api_call)
6565
end
6666

67+
def delete(query_parameters = {})
68+
@api_call.delete(endpoint_path, query_parameters)
69+
end
70+
6771
private
6872

6973
def endpoint_path(operation = nil)

lib/typesense/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Typesense
4-
VERSION = '0.8.0'
4+
VERSION = '0.9.0'
55
end

spec/typesense/documents_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@
194194
end
195195
end
196196

197+
describe '#delete' do
198+
it 'delete documents in a collection' do
199+
stub_request(:delete, Typesense::ApiCall.new(typesense.configuration).send(:uri_for, '/collections/companies/documents', typesense.configuration.nodes[0]))
200+
.with(headers: {
201+
'X-Typesense-Api-Key' => typesense.configuration.api_key,
202+
'Content-Type' => 'application/json'
203+
},
204+
query: {
205+
filter_by: 'field:=value'
206+
})
207+
.to_return(status: 200, body: '{}', headers: { 'Content-Type': 'application/json' })
208+
209+
result = companies_documents.delete(filter_by: 'field:=value')
210+
211+
expect(result).to eq({})
212+
end
213+
end
214+
197215
describe '#search' do
198216
let(:search_parameters) do
199217
{

0 commit comments

Comments
 (0)