Skip to content

Instantly share code, notes, and snippets.

@tomatolog
Created February 29, 2016 06:52
Show Gist options
  • Select an option

  • Save tomatolog/67c67beb0194bba51af1 to your computer and use it in GitHub Desktop.

Select an option

Save tomatolog/67c67beb0194bba51af1 to your computer and use it in GitHub Desktop.
mysql_query("SET AUTOCOMMIT=0", $c2) or die("sphinx SET AUTOCOMMIT failed: " . mysql_error($c2));
mysql_query("TRUNCATE RTINDEX rt", $c2) or die("sphinx TRUNCATE failed: " . mysql_error($c2));
$r1 = mysql_unbuffered_query("SELECT id, title, UNCOMPRESS(content), CRC32(title) FROM index", $c1) or die("mysql fetch failed: " . mysql_error($c1));
while (list($id, $title, $content, $gid) = mysql_fetch_row($r1))
{
$t += strlen($title) + strlen($content);
$title = mysql_real_escape_string($title);
$content = mysql_real_escape_string($content);
mysql_query("INSERT INTO rt (id, title, content, gid) VALUES ($id, '$title', '$content', $gid)", $c2) or die("sphinx insert failed: " . mysql_error($c2));
if ( ++$n==1000 )
{
mysql_query("COMMIT", $c2) or die("sphinx commit failed:" . mysql_error($c2));
$nn += $n;
$n = 0;
print("$nn rows\r");
}
}
mysql_query("COMMIT", $c2) or die("sphinx test failed: " . mysql_error($c2));
$nn += $n;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment