3 namespace BookStack\Console\Commands;
5 use BookStack\Entities\Models\Entity;
6 use BookStack\Search\SearchIndex;
7 use Illuminate\Console\Command;
8 use Illuminate\Support\Facades\DB;
10 class RegenerateSearchCommand extends Command
13 * The name and signature of the console command.
17 protected $signature = 'bookstack:regenerate-search
18 {--database= : The database connection to use}';
21 * The console command description.
25 protected $description = 'Re-index all content for searching';
28 * Execute the console command.
30 public function handle(SearchIndex $searchIndex): int
32 $connection = DB::getDefaultConnection();
33 if ($this->option('database') !== null) {
34 DB::setDefaultConnection($this->option('database'));
37 $searchIndex->indexAllEntities(function (Entity $model, int $processed, int $total): void {
38 $this->info('Indexed ' . class_basename($model) . ' entries (' . $processed . '/' . $total . ')');
41 DB::setDefaultConnection($connection);
42 $this->line('Search index regenerated!');
44 return static::SUCCESS;