diff --git a/src/Engines/AbstractEngine.php b/src/Engines/AbstractEngine.php index 7606695..786a311 100644 --- a/src/Engines/AbstractEngine.php +++ b/src/Engines/AbstractEngine.php @@ -181,6 +181,11 @@ protected function sortByIsValid(): bool return $field && ($field['sort'] ?? false); } + + public function deleteByIds(Collection $ids): array + { + return []; + } abstract public function get(): mixed; diff --git a/src/Engines/TypesenseEngine.php b/src/Engines/TypesenseEngine.php index 8f43527..6511b60 100644 --- a/src/Engines/TypesenseEngine.php +++ b/src/Engines/TypesenseEngine.php @@ -3,8 +3,10 @@ namespace Lunar\Search\Engines; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; use Laravel\Scout\EngineManager; +use Lunar\Models\Product; use Lunar\Search\Data\SearchFacet; use Lunar\Search\Data\SearchHit; use Lunar\Search\Data\SearchResults; @@ -134,7 +136,7 @@ protected function buildSearch(array $options): array $requests = []; $facets = $this->getFacetConfig(); - + foreach ($searchQueries as $searchQuery) { $filters = collect($options['filter_by']); @@ -195,6 +197,15 @@ protected function buildSearch(array $options): array return $requests; } + public function deleteByIds(Collection $ids): array + { + $typesense = app(EngineManager::class)->engine('typesense'); + $index = (new Product)->searchableAs(); + return $typesense->getCollections()[$index]->documents->delete([ + 'filter_by' => 'id: ['.$ids->join(',').']', + ]); + } + protected function getFieldConfig(): array {