Created
February 11, 2023 07:54
-
-
Save KarelWintersky/3600244b5787bc67801c76bcf8c0e2ed to your computer and use it in GitHub Desktop.
TopPopularKeywords3000000.csv insert to Manticore Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// требует | |
// composer require karelwintersky/arris | |
use Arris\DB; | |
use Arris\Toolkit\SphinxToolkit; | |
require_once __DIR__ . '/vendor/autoload.php'; | |
$starttime = microtime(true); | |
try { | |
$CONFIG = [ | |
'hostname' => '127.0.0.1, | |
'database' => NULL, | |
'username' => 'root', | |
'password' => '', | |
'port' => 9306, | |
'charset' => NULL, | |
'charset_collate' => NULL | |
]; | |
\Arris\Database\DBMultiConnector::init('SEARCHD', $CONFIG); | |
$pdo = \Arris\Database\DBMultiConnector::getConnection('SEARCHD'); | |
$CSV = 'TopPopularKeywords3000000.csv'; | |
$f = fopen($CSV, "r+"); | |
$i = 1; | |
$pdo->query("CREATE TABLE IF NOT EXISTS keywords(keyword text, freqBroad uint, freqExact uint)"); | |
$pdo->query("TRUNCATE TABLE keywords"); | |
echo "Table created and truncated with reconfigure... sleep for 1 second". PHP_EOL . PHP_EOL; | |
echo "Table created and truncated with reconfigure... sleep for 1 second". PHP_EOL . PHP_EOL; | |
sleep(1); | |
$msth = $pdo->prepare("insert into keywords(keyword, freqBroad, freqExact) values (:phrase, :freqBroad, :freqExact) " ); | |
while (($data = fgetcsv($f, 100000, ";")) !== FALSE) { | |
$msth->bindValue("phrase", $data[ 0 ]); // .Phrase = 0 | |
$msth->bindValue("freqBroad", $data[ 3 ], PDO::PARAM_INT); // BroadMatchCnt = 3 | |
$msth->bindValue("freqExact", $data[ 6 ], PDO::PARAM_INT); // "ExactMatchWithFixedWordOrderCnt" = 6 | |
$msth->execute(); | |
echo $i . " : " . $data[ 0 ] . PHP_EOL; | |
$i++; | |
} | |
} catch (\Exception $e) { | |
CLIConsole::say($e->getMessage()); | |
die; | |
} | |
echo PHP_EOL; | |
$report = PHP_EOL; | |
$report .= "Memory consumed: " . memory_get_usage() . " bytes. ". PHP_EOL; | |
$report .= "Time consumed: " . round(microtime(true) - $starttime, 1) . " seconds. ".PHP_EOL; | |
echo $report; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment