3 namespace BookStack\Console\Commands;
5 use BookStack\Entities\SearchService;
7 use Illuminate\Console\Command;
9 class RegenerateSearch extends Command
12 * The name and signature of the console command.
16 protected $signature = 'bookstack:regenerate-search {--database= : The database connection to use.}';
19 * The console command description.
23 protected $description = 'Re-index all content for searching';
25 protected $searchService;
28 * Create a new command instance.
30 * @param SearchService $searchService
32 public function __construct(SearchService $searchService)
34 parent::__construct();
35 $this->searchService = $searchService;
39 * Execute the console command.
43 public function handle()
45 $connection = DB::getDefaultConnection();
46 if ($this->option('database') !== null) {
47 DB::setDefaultConnection($this->option('database'));
48 $this->searchService->setConnection(DB::connection($this->option('database')));
51 $this->searchService->indexAllEntities();
52 DB::setDefaultConnection($connection);
53 $this->comment('Search index regenerated');