3 namespace BookStack\Console\Commands;
5 use BookStack\Entities\EntityProvider;
6 use BookStack\Entities\Models\Entity;
7 use BookStack\Search\Vectors\SearchVector;
8 use BookStack\Search\Vectors\StoreEntityVectorsJob;
9 use Illuminate\Console\Command;
11 class RegenerateVectorsCommand extends Command
14 * The name and signature of the console command.
18 protected $signature = 'bookstack:regenerate-vectors';
21 * The console command description.
25 protected $description = 'Re-index vectors for all content in the system';
28 * Execute the console command.
30 public function handle(EntityProvider $entityProvider)
32 // TODO - Add confirmation before run regarding deletion/time/effort/api-cost etc...
33 SearchVector::query()->delete();
35 $types = $entityProvider->all();
36 foreach ($types as $type => $typeInstance) {
37 $this->info("Creating jobs to store vectors for {$type} data...");
38 /** @var Entity[] $entities */
39 $typeInstance->newQuery()->chunkById(100, function ($entities) {
40 foreach ($entities as $entity) {
41 dispatch(new StoreEntityVectorsJob($entity));