3 namespace BookStack\Console\Commands;
5 use BookStack\Entities\SearchService;
6 use Illuminate\Console\Command;
8 class RegenerateSearch extends Command
11 * The name and signature of the console command.
15 protected $signature = 'bookstack:regenerate-search {--database= : The database connection to use.}';
18 * The console command description.
22 protected $description = 'Re-index all content for searching';
24 protected $searchService;
27 * Create a new command instance.
29 * @param \BookStack\Entities\SearchService $searchService
31 public function __construct(SearchService $searchService)
33 parent::__construct();
34 $this->searchService = $searchService;
38 * Execute the console command.
42 public function handle()
44 $connection = \DB::getDefaultConnection();
45 if ($this->option('database') !== null) {
46 \DB::setDefaultConnection($this->option('database'));
47 $this->searchService->setConnection(\DB::connection($this->option('database')));
50 $this->searchService->indexAllEntities();
51 \DB::setDefaultConnection($connection);
52 $this->comment('Search index regenerated');