-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #734 from rapidez/feature/products-index
[Instantsearch] Scout indexing products & categories
- Loading branch information
Showing
15 changed files
with
251 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Rapidez\Core\Events\IndexAfterEvent; | ||
use Rapidez\Core\Events\IndexBeforeEvent; | ||
use Rapidez\Core\Facades\Rapidez; | ||
use Rapidez\Core\Models\Traits\Searchable; | ||
|
||
class IndexCommand extends Command | ||
{ | ||
protected $signature = 'rapidez:index {--t|types= : To specify types of models to index, separated by commas} {--s|store= : To specify store IDs from Magento, separated by commas}'; | ||
|
||
protected $description = 'Index all searchable models into ElasticSearch'; | ||
|
||
public function handle() | ||
{ | ||
$baseSearchableModels = collect(config('rapidez.models')) | ||
->filter(fn ($class) => in_array(Searchable::class, class_uses_recursive($class))) | ||
->merge(config('rapidez.indexer.extra_models')); | ||
|
||
$types = $this->option('types') | ||
? $baseSearchableModels->only(explode(',', $this->option('types'))) | ||
: $baseSearchableModels; | ||
|
||
$stores = $this->option('store') | ||
? Rapidez::getStores(explode(',', $this->option('store'))) | ||
: Rapidez::getStores(); | ||
|
||
$this->call('cache:clear'); | ||
|
||
IndexBeforeEvent::dispatch($this); | ||
|
||
foreach ($stores as $store) { | ||
Rapidez::setStore($store); | ||
|
||
$this->line('Store: ' . $store['name']); | ||
|
||
foreach ($types as $type => $model) { | ||
config()->set('rapidez.index', $type); | ||
|
||
$this->call('scout:import', [ | ||
'searchable' => $model, | ||
]); | ||
} | ||
} | ||
|
||
IndexAfterEvent::dispatch($this); | ||
} | ||
} |
Oops, something went wrong.