Skip to content

Commit

Permalink
Add method to delete multiple by id
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Nov 8, 2024
1 parent 67a13d7 commit 0fe6650
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Engines/AbstractEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 12 additions & 1 deletion src/Engines/TypesenseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,7 +136,7 @@ protected function buildSearch(array $options): array
$requests = [];

$facets = $this->getFacetConfig();

foreach ($searchQueries as $searchQuery) {

$filters = collect($options['filter_by']);
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 0fe6650

Please sign in to comment.