info('Creating Manticore Search indexes...'); $this->client = ManticoreClientFactory::make(config('search.drivers.manticore', [])); try { $this->client->nodes()->status(); } catch (\Throwable $e) { $this->error('Failed to connect to Manticore Search: '.$e->getMessage()); $this->info('Check the configured host, authentication, and whether Manticore is running.'); return self::FAILURE; } $configuredNames = config('search.drivers.manticore.indexes', []); $hasErrors = false; foreach (ManticoreIndexRegistry::definitions() as $logical => $schema) { $indexName = (string) ($configuredNames[$logical] ?? $logical.'_rt'); if (! $this->createIndex($indexName, $schema, (bool) $this->option('drop'))) { $hasErrors = true; } } if ($hasErrors) { $this->error('Some Manticore tables could not be created.'); return self::FAILURE; } $this->info('All Manticore Search tables are ready.'); return self::SUCCESS; } /** @param array $schema */ protected function createIndex(string $indexName, array $schema, bool $dropExisting): bool { $tables = $this->client->tables(); try { if ($dropExisting) { $this->info("Dropping {$indexName}..."); $tables->drop(['index' => $indexName, 'body' => ['silent' => true]]); } $tables->create(['index' => $indexName, 'body' => $schema]); $this->info("Created {$indexName}."); return true; } catch (ResponseException $e) { if (str_contains($e->getMessage(), 'already exists')) { $this->warn("{$indexName} already exists; use --drop during a maintenance rebuild."); return true; } if (str_contains($e->getMessage(), 'data_dir')) { $this->error("Failed to create {$indexName}: configure a writable Manticore data_dir."); } else { $this->error("Failed to create {$indexName}: ".$e->getMessage()); } return false; } catch (\Throwable $e) { $this->error("Failed to create {$indexName}: ".$e->getMessage()); return false; } } }