Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?php
$category_file = $argv[1];
$rc = 1;
$startTimeAll = microtime(true);
$fp = fopen($category_file, 'r');
while(!feof($fp)){
$line = fgets($fp);
$line = str_replace(array("\r\n","\r","\n"),'',$line);
if($line != ""){
$startTime = microtime(true);
$query = $line;
$json_doc = array(
"from" => "0",
"size" => "0",
"fields" => array("id"),
"query" => array(
"multi_match" => array(
"query" => "\"" . $query . "\"",
"fields" => array("title","text"),
),
)
);
$qry = json_encode($json_doc);
$url="http://localhost:9200/wikipedia/text/_search";
$req="GET";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, 9200);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $req);
curl_setopt($ch, CURLOPT_POSTFIELDS, $qry);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec ($ch);
curl_close ($ch);
$endTime = microtime(true);
$elapsedTime = $endTime - $startTime;
//$decode_data = json_decode( $data, true);
//echo $line . "," . $elapsedTime . "\n";
echo $rc . "," . $elapsedTime . "\n";
$rc++;
}
}
$endTimeAll = microtime(true);
$elapsedTimeAll = $endTimeAll - $startTimeAll;
$rc--;
echo "Total(" . $rc . ") = " . $elapsedTimeAll . "\n";
echo "Average = " . $elapsedTimeAll/$rc . "\n";
fclose($fp)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment