diff --git a/src/Console/ReindexSearchCommand.php b/src/Console/ReindexSearchCommand.php new file mode 100644 index 0000000..ab7960a --- /dev/null +++ b/src/Console/ReindexSearchCommand.php @@ -0,0 +1,54 @@ +newElasticHandle($searchableModel); + } + } + + private function newElasticHandle($searchableModel) + { + $searchableModelObject = new $searchableModel; + + $this->info("\nIndexing " . $searchableModel); + + $indexConfiguratorClass = $searchableModelObject->indexConfigurator; + + $indexConfigurator = new $indexConfiguratorClass(); + + if (ElasticClient::indices()->exists(['index' => $indexConfigurator->getName()])) { + + $this->call('elastic:drop-index', [ + 'index-configurator' => $searchableModelObject->indexConfigurator + ]); + } + + $this->call('elastic:create-index', [ + 'index-configurator' => $searchableModelObject->indexConfigurator + ]); + $this->call('elastic:update-mapping', [ + 'model' => $searchableModel + ]); + + $this->call('scout:import', [ + 'model' => $searchableModel + ]); + } +} \ No newline at end of file diff --git a/src/ScoutElasticServiceProvider.php b/src/ScoutElasticServiceProvider.php index 7b5e89e..e527291 100644 --- a/src/ScoutElasticServiceProvider.php +++ b/src/ScoutElasticServiceProvider.php @@ -15,6 +15,7 @@ use ScoutElastic\Console\ElasticUpdateMappingCommand; use ScoutElastic\Console\IndexConfiguratorMakeCommand; +use ScoutElastic\Console\ReindexSearchCommand; use ScoutElastic\Console\SearchableModelMakeCommand; use ScoutElastic\Console\SearchRuleMakeCommand; use ScoutElastic\Console\AggregateRuleMakeCommand; @@ -43,7 +44,8 @@ public function boot() ElasticIndexUpdateCommand::class, ElasticIndexDropCommand::class, ElasticUpdateMappingCommand::class, - ElasticMigrateCommand::class + ElasticMigrateCommand::class, + ReindexSearchCommand::class ]); require_once __DIR__.'/Macros.php';