Save workspace changes
This commit is contained in:
@@ -59,6 +59,7 @@ class ConfigureMeilisearchIndex extends Command
|
||||
'has_missing_thumbnails',
|
||||
'category',
|
||||
'content_type',
|
||||
'published_as_type',
|
||||
'tags',
|
||||
'author_id',
|
||||
'orientation',
|
||||
@@ -69,6 +70,9 @@ class ConfigureMeilisearchIndex extends Command
|
||||
{
|
||||
$prefix = config('scout.prefix', '');
|
||||
$indexName = $prefix . (string) $this->option('index');
|
||||
$indexSettings = $this->configuredIndexSettings($indexName);
|
||||
$sortableAttributes = $this->configuredSortableAttributes($indexSettings);
|
||||
$filterableAttributes = $this->configuredFilterableAttributes($indexSettings);
|
||||
|
||||
/** @var MeilisearchClient $client */
|
||||
$client = app(MeilisearchClient::class);
|
||||
@@ -79,12 +83,12 @@ class ConfigureMeilisearchIndex extends Command
|
||||
|
||||
// ── Sortable attributes ───────────────────────────────────────────────
|
||||
$this->line(' → Updating sortableAttributes…');
|
||||
$task = $index->updateSortableAttributes(self::SORTABLE_ATTRIBUTES);
|
||||
$task = $index->updateSortableAttributes($sortableAttributes);
|
||||
$this->line(" Task uid: {$task['taskUid']}");
|
||||
|
||||
// ── Filterable attributes ─────────────────────────────────────────────
|
||||
$this->line(' → Updating filterableAttributes…');
|
||||
$task2 = $index->updateFilterableAttributes(self::FILTERABLE_ATTRIBUTES);
|
||||
$task2 = $index->updateFilterableAttributes($filterableAttributes);
|
||||
$this->line(" Task uid: {$task2['taskUid']}");
|
||||
|
||||
$this->info('Done. Meilisearch will process these tasks asynchronously.');
|
||||
@@ -92,4 +96,46 @@ class ConfigureMeilisearchIndex extends Command
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function configuredIndexSettings(string $indexName): array
|
||||
{
|
||||
$settings = config('scout.meilisearch.index-settings', []);
|
||||
|
||||
if (! is_array($settings)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$configured = $settings[$indexName] ?? [];
|
||||
|
||||
return is_array($configured) ? $configured : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $indexSettings
|
||||
* @return list<string>
|
||||
*/
|
||||
private function configuredSortableAttributes(array $indexSettings): array
|
||||
{
|
||||
$configured = $indexSettings['sortableAttributes'] ?? null;
|
||||
|
||||
return is_array($configured) && $configured !== []
|
||||
? array_values($configured)
|
||||
: self::SORTABLE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $indexSettings
|
||||
* @return list<string>
|
||||
*/
|
||||
private function configuredFilterableAttributes(array $indexSettings): array
|
||||
{
|
||||
$configured = $indexSettings['filterableAttributes'] ?? null;
|
||||
|
||||
return is_array($configured) && $configured !== []
|
||||
? array_values($configured)
|
||||
: self::FILTERABLE_ATTRIBUTES;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user