Skip to content

Commit

Permalink
Merge pull request #734 from rapidez/feature/products-index
Browse files Browse the repository at this point in the history
[Instantsearch] Scout indexing products & categories
  • Loading branch information
royduin authored Feb 18, 2025
2 parents 8a9b188 + a76853e commit e97e3ed
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 551 deletions.
6 changes: 6 additions & 0 deletions config/rapidez/indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
// VISIBILITY_IN_SEARCH = 3
// VISIBILITY_BOTH = 4
'visibility' => [2, 3, 4],

// The Rapidez indexer will automatically start indexing any models with the Searchable trait that exist within `models.php`.
// If you want to add extra models you can add them here. Only Eloquent models are supported.
'extra_models' => [
// 'book' => \App\Models\Book::class,
],
];
6 changes: 4 additions & 2 deletions resources/views/components/listing.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
label: window.config.translations.newest,
field: 'created_at',
order: 'desc',
value: config.index+'_created_at_desc',
{{-- TODO: Extract this somewhere? --}}
value: config.index_prefix + '_products_' + config.store + '_created_at_desc',
key: '_created_at_desc'
}]"
v-cloak
Expand All @@ -23,7 +24,8 @@
<ais-instant-search
v-if="loaded"
:search-client="listingSlotProps.searchClient"
:index-name="config.index"
{{-- TODO: Extract this somewhere? --}}
:index-name="config.index_prefix + '_products_' + config.store"
:routing="listingSlotProps.routing"
>
<ais-configure :filters="{!! $query !!}"/>
Expand Down
62 changes: 0 additions & 62 deletions src/Commands/ElasticsearchIndexCommand.php

This file was deleted.

151 changes: 0 additions & 151 deletions src/Commands/ElasticsearchIndexer.php

This file was deleted.

41 changes: 0 additions & 41 deletions src/Commands/IndexCategoriesCommand.php

This file was deleted.

51 changes: 51 additions & 0 deletions src/Commands/IndexCommand.php
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);
}
}
Loading

0 comments on commit e97e3ed

Please sign in to comment.