Skip to content

Commit cba9dba

Browse files
committed
Added support for importing documents via JSONL directly
1 parent 4b3441a commit cba9dba

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/typesense/documents.rb

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def create(document)
1616

1717
def create_many(documents)
1818
documents_in_jsonl_format = documents.map { |document| JSON.dump(document) }.join("\n")
19+
import(documents_in_jsonl_format)
20+
end
21+
22+
def import(documents_in_jsonl_format)
1923
@api_call.post(endpoint_path('import'), as_json: false, body: documents_in_jsonl_format)
2024
end
2125

lib/typesense/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Typesense
4-
VERSION = '0.5.4'
4+
VERSION = '0.5.5'
55
end

spec/typesense/documents_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@
7373
end
7474
end
7575

76+
describe '#import' do
77+
it 'imports documents in JSONL format' do
78+
stub_request(:post, Typesense::ApiCall.new(typesense.configuration).send(:uri_for, '/collections/companies/documents/import', typesense.configuration.nodes[0]))
79+
.with(body: "#{JSON.dump(document)}\n#{JSON.dump(document)}",
80+
headers: {
81+
'X-Typesense-Api-Key' => typesense.configuration.api_key
82+
})
83+
.to_return(status: 200, body: '{}', headers: { 'Content-Type': 'application/json' })
84+
85+
result = companies_documents.import("#{JSON.dump(document)}\n#{JSON.dump(document)}")
86+
87+
expect(result).to eq({})
88+
end
89+
end
90+
7691
describe '#export' do
7792
it 'exports all documents in a collection as an array' do
7893
stub_request(:get, Typesense::ApiCall.new(typesense.configuration).send(:uri_for, '/collections/companies/documents/export', typesense.configuration.nodes[0]))

0 commit comments

Comments
 (0)