Closed Codnpix closed 3 months ago
Which version of the driver are you using. The newest version should support table prefixes
I think I installed the last version, I just ran composer require teamtnt/laravel-scout-tntsearch-driver
(today).
My composer.json says :
"teamtnt/laravel-scout-tntsearch-driver": "^7.0",
Here is a copy of my vendor/teamtnt/laravel-scout-tntsearch-driver/console/ImportCommand.php@handle() function :
public function handle(Dispatcher $events)
{
$class = $this->argument('model');
$model = new $class();
$tnt = new TNTSearch();
$driver = $model->getConnectionName() ?: config('database.default');
$config = config('scout.tntsearch') + config("database.connections.$driver");
$tnt->loadConfig($config);
$tnt->setDatabaseHandle(app('db')->connection($driver)->getPdo());
$indexer = $tnt->createIndex($model->searchableAs().'.index');
$indexer->setPrimaryKey($model->getKeyName());
$availableColumns = \Schema::getColumnListing($model->getTable());
$desiredColumns = array_keys($model->toSearchableArray());
$fields = implode(', ', array_intersect($desiredColumns, $availableColumns));
$query = "{$model->getKeyName()}, $fields";
if ($fields == '') {
$query = '*';
}
$indexer->query("SELECT $query FROM {$model->getTable()};");
$indexer->run();
$this->info('All ['.$class.'] records have been imported.');
}
I don't see the part that should handle prefix, and yet I see it on the corresponding file in the github repo (branch:master) :
public function handle(Dispatcher $events)
{
$class = $this->argument('model');
$model = new $class();
$tnt = new TNTSearch();
$driver = $model->getConnectionName() ?: config('database.default');
$config = config('scout.tntsearch') + config("database.connections.$driver");
$tablePrefix = $config['prefix'] ?? '';
$tableName = $tablePrefix.$model->getTable();
$tnt->loadConfig($config);
$tnt->setDatabaseHandle(app('db')->connection($driver)->getPdo());
$indexer = $tnt->createIndex($model->searchableAs().'.index');
$indexer->setPrimaryKey($model->getKeyName());
$availableColumns = \Schema::getColumnListing($model->getTable());
$desiredColumns = array_keys($model->toSearchableArray());
$fields = implode(', ', array_intersect($desiredColumns, $availableColumns));
$query = "{$model->getKeyName()}, $fields";
if ($fields == '') {
$query = '*';
}
$indexer->query("SELECT $query FROM {$tableName};");
$indexer->run();
$this->info('All ['.$class.'] records have been imported.');
}
So it looks like the package that I installed is not the same. What should I do ?
EDIT : For now I just copied the functions from your repo that were different from those in my /vendor. It's working. But I'm not sure I should solve the problem like that...
Hello, I tried to create the indexes I need for research from my tables. Problem is, all my tables have a prefix, and it doesn't seems to be taken into account : the command ```php artisan tntsearch:import "App\Models\Mymodel" returns an error that my table (whithout prefix) doesn't exist.
However I have the
SCOUT_PREFIX=gb_
value entered in my .envMy tntsearch config in scout.php looks like this :
I also tried to add a 'prefix' key like that :
But none of that is working for me. I don't know if I'm doing something wrong or if the driver doesn't provides this feature. I didn't find any explicit documentation about this usecase. Thank you for your help.