106 lines
2.9 KiB
PHP
106 lines
2.9 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
// connect to es
|
|
$client = require 'connect-es.php';
|
|
$index_status = require 'checkindex.php';
|
|
?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title><?php echo $es_site_title." v".$site_version ?></title>
|
|
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> -->
|
|
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
|
|
<link rel="stylesheet" type="text/css" href="css/gmo.css">
|
|
</head>
|
|
<body>
|
|
<h2><?php echo $es_site_title ?></h2>
|
|
<h6><?php echo $site_copyright ?></h6>
|
|
<br>
|
|
<?php
|
|
function displayInfoSearch($response){
|
|
|
|
echo "<p>";
|
|
printf("Total docs: %d\n", $response['hits']['total']['value']);
|
|
echo "<br>";
|
|
printf("Max score : %.4f\n", $response['hits']['max_score']);
|
|
echo "<br>";
|
|
printf("Took : %d ms\n", $response['took']);
|
|
echo "</p>";
|
|
}
|
|
|
|
function displayResult($response){
|
|
$hits=$response['hits']['total']['value'];
|
|
$result = null;
|
|
$i = 0;
|
|
while ($i < $hits) {
|
|
$result[$i] = $response['hits']['hits'][$i]['_source'];
|
|
$i++;
|
|
}
|
|
$row = 0;
|
|
foreach ($result as $key => $value) {
|
|
//while ($row < 15) {
|
|
echo $value['id'] . " : ";
|
|
echo $value['firstname'] . " : ";
|
|
echo $value['lastname'] . " : ";
|
|
echo $value['email'] . "<br>";
|
|
//}
|
|
//$row++;
|
|
}
|
|
echo "<br>";
|
|
}
|
|
|
|
//
|
|
if ($index_status == 200) {
|
|
// search one item
|
|
$params = [
|
|
'index' => $es_index,
|
|
'from' => 0, // <--- Start at #1
|
|
'size' => 10,
|
|
'body' => [
|
|
'query' => [
|
|
'match' => [
|
|
'firstname' => 'chantal'
|
|
]
|
|
]
|
|
]
|
|
];
|
|
$response = $client->search($params);
|
|
echo "<b>Result of the research 'match (chantal)'</b>";
|
|
displayInfoSearch($response);
|
|
displayResult($response);
|
|
|
|
// Search wildcard
|
|
$params = [
|
|
'index' => $es_index,
|
|
'body' => [
|
|
'query' => [
|
|
'wildcard' => ["firstname" => "yv*"]
|
|
]
|
|
]
|
|
];
|
|
$response = $client->search($params);
|
|
echo "<b>Result of the research 'wildcard (yv*)'</b>";
|
|
displayInfoSearch($response);
|
|
displayResult($response);
|
|
|
|
// Search all item
|
|
$params = [
|
|
'index' => $es_index,
|
|
'body' => '{
|
|
"from": 0,
|
|
"size": 100, //dispay 100 result (default is 10)
|
|
"query": {
|
|
"match_all": {}
|
|
}
|
|
}',
|
|
];
|
|
$response = $client->search($params);
|
|
echo "<b>Result of the research 'match_all'</b>";
|
|
displayInfoSearch($response);
|
|
displayResult($response);
|
|
}
|
|
else {
|
|
echo "Problem with index <b>".$es_index."</b> (".$index_status.")";
|
|
}
|
|
?>
|