Skip to content

Commit a0b140d

Browse files
authored
Merge pull request #5 from typesense/bulk-deletes
Support for bulk delete
2 parents aae2588 + ed804cf commit a0b140d

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Here are some examples that walk you through how to use the client: [doc/example
2020

2121
| Typesense Server | typesense-php |
2222
|------------------|----------------|
23+
| \>= v0.16.0 | \>= v4.2.0 |
2324
| \>= v0.16.0 | \>= v4.1.0 |
2425
| \>= v0.15.0 | \>= v4.0.0 |
2526

examples/collection_operations.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
echo "--------Delete Document-------\n";
164164
echo "\n";
165165
echo "--------Import Documents-------\n";
166-
$docsToImport = [];
166+
$docsToImport = [];
167167
$exportedDocStrsArray = explode('\n', $exportedDocStrs);
168168
foreach ($exportedDocStrsArray as $exportedDocStr) {
169169
$docsToImport[] = json_decode($exportedDocStr, true);
@@ -193,6 +193,10 @@
193193
print_r($upsertRes);
194194
echo "--------Upsert Documents-------\n";
195195
echo "\n";
196+
echo "--------Bulk Delete Documents-------\n";
197+
print_r($client->collections['books']->documents->delete(['filter_by' => 'publication_year:=2008']));
198+
echo "--------Bulk Delete Documents-------\n";
199+
echo "\n";
196200
echo "--------Delete Collection-------\n";
197201
print_r($client->collections['books']->delete());
198202
echo "--------Delete Collection-------\n";

src/Documents.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Documents implements \ArrayAccess
4141
public function __construct(string $collectionName, ApiCall $apiCall)
4242
{
4343
$this->collectionName = $collectionName;
44-
$this->apiCall = $apiCall;
44+
$this->apiCall = $apiCall;
4545
}
4646

4747
/**
@@ -150,6 +150,17 @@ public function export(): string
150150
return $this->apiCall->get($this->endPointPath('export'), [], false);
151151
}
152152

153+
/**
154+
* @param array $queryParams
155+
*
156+
* @return array
157+
* @throws TypesenseClientError|GuzzleException
158+
*/
159+
public function delete(array $queryParams = []): array
160+
{
161+
return $this->apiCall->delete($this->endPointPath(), true, $queryParams);
162+
}
163+
153164
/**
154165
* @param array $searchParams
155166
*

src/Lib/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function __construct(array $config)
9898
$this->retryIntervalSeconds = (float)($config['retry_interval_seconds'] ?? 1.0);
9999

100100
$this->logLevel = $config->logLevel ?? Logger::WARNING;
101-
$this->logger = new Logger('typesense');
101+
$this->logger = new Logger('typesense');
102102
$this->logger->pushHandler(new StreamHandler('php://stdout', $this->logLevel));
103103
}
104104

0 commit comments

Comments
 (0)