Skip to content

Commit c63ad17

Browse files
authored
Add bulk delete (#4)
1 parent 61ea1fb commit c63ad17

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Laravel Scout Typesense Engine
1414
<p align="center">
15-
<img src="https://banners.beyondco.de/typesense%2Flaravel-typesense.png?theme=dark&packageManager=composer+require&packageName=typesense%2Flaravel-typesense&pattern=architect&style=style_1&description=Easy+typesense+support+for+Laravel+Scout&md=1&showWatermark=0&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg">
15+
<img src="https://banners.beyondco.de/typesense%2Flaravel-typesense.png?theme=dark&packageManager=composer+require&packageName=typesense%2Flaravel-typesense&pattern=architect&style=style_1&description=Easy+Typesense+support+for+Laravel+Scout&md=1&showWatermark=0&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg">
1616
</p>
1717

1818
This package makes it easy to add full text search support to your models with Laravel 7.\* to 8.\*.
@@ -173,6 +173,7 @@ $posts->searchable();
173173
and changing the config/scout.php config key from `typesensesearch` to `typesense`
174174
- Instead of importing `Devloops\LaravelTypesense\*`, you should import `Typesense\LaravelTypesense\*`
175175
- Instead of models implementing `Devloops\LaravelTypesense\Interfaces\TypesenseSearch`, they should implement `Typesense\LaravelTypesense\Interfaces\TypesenseDocument`
176+
- In the rare case where the `TypesenseEngine` method `delete` is called directly, all the model instances passed to the method must now belong to the same Typesense index
176177

177178
## Authors
178179
This package was based off of https://github.com/AbdullahFaqeir and his company DevLoops' work, https://github.com/devloopsnet/laravel-scout-typesense-engine. Other contributors include:

src/Engines/TypesenseEngine.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ public function update($models): void
6060
*/
6161
public function delete($models): void
6262
{
63-
$models->each(function (Model $model) {
64-
$collectionIndex = $this->typesense->getCollectionIndex($model);
63+
$collection = $this->typesense->getCollectionIndex($models->first());
64+
65+
$ids = $models->map->getScoutKey()->values()->all();
66+
$ids = join(', ', $ids);
6567

66-
$this->typesense->deleteDocument($collectionIndex, $model->{$model->getKey()});
67-
});
68+
$query = [
69+
'filter_by' => "{$models->first()->getScoutKeyName()}: [${ids}]",
70+
];
71+
$this->typesense->deleteDocuments($collection, $query);
6872
}
6973

7074
/**
@@ -263,4 +267,4 @@ public function deleteIndex($name): array
263267
return $this->typesense->deleteCollection($name);
264268
}
265269

266-
}
270+
}

0 commit comments

Comments
 (0)