Skip to content

Commit e2ab521

Browse files
- Rewrote create_many in documents in camelCase to be createMany().
- import() method now takes JSONL as parameter instead of array of documents.
1 parent ff810bb commit e2ab521

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

examples/collection_operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
$docsToImport[] = json_decode($exportedDocStr, true);
130130
}
131131
$importRes =
132-
$client->collections['books']->documents->create_many($docsToImport);
132+
$client->collections['books']->documents->createMany($docsToImport);
133133
print_r($importRes);
134134
echo "--------Import Documents-------\n";
135135
echo "\n";

src/Documents.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,24 @@ public function create(array $document): array
7676
* @return array
7777
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
7878
*/
79-
public function create_many(array $documents): array
79+
public function createMany(array $documents): array
8080
{
81-
$res = $this->import($documents);
81+
$res = $this->import(implode("\n", $documents));
8282
return array_map(static function ($item) {
8383
return json_decode($item, true);
8484
}, explode("\n", $res));
8585
}
8686

8787
/**
88-
* @param array $documents
88+
* @param string $documents
8989
*
9090
* @return string
9191
* @throws \Typesence\Exceptions\TypesenseClientError
9292
* @throws \GuzzleHttp\Exception\GuzzleException
9393
*/
94-
public function import(array $documents): string
94+
public function import(string $documents): string
9595
{
96-
$documentsStr = [];
97-
foreach ($documents as $document) {
98-
$documentsStr[] = json_encode($document);
99-
}
100-
$docsImport = implode("\n", $documentsStr);
101-
return $this->apiCall->post($this->endPointPath('import'), $docsImport, false);
96+
return $this->apiCall->post($this->endPointPath('import'), $documents, false);
10297
}
10398

10499
/**

0 commit comments

Comments
 (0)