ClientBuilder Elasticsearch (ok)
<?php
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
if (isset($_GET['keyword'])) {
$search = '{
"bool": {
"must": [
{
"multi_match": {
"query": "'.$_GET['keyword'].'",
"type": "phrase",
"fields": [
"post_title^1",
"post_content^2",
"terms.pointfinderltypes.name^1",
"terms.ep_custom_result.name^9999"
]
}
}
]
}
}';
}
if (isset($_GET['coordinates'])&& $_GET['sort']==1){
$sort_by_coordinates =
'{
"_geo_distance" : {
"geo_point.location" : "'.$_GET['coordinates'].'",
"order" : "asc",
"unit" : "km"
}
},
"_score"';
}
$filters = '{"match": {"post_type.raw": "listing"}}';
if (isset($_GET['listing'])) {
$filters .= ',{"match": {"post_id": '.$_GET['listing'].'}}';
}
if (isset($_GET['coordinates'])&& (isset($_GET['range']))){
$filters .=
',{
"geo_distance": {
"distance": "'.$_GET['range'].'km",
"geo_point.location": "'.$_GET['coordinates'].'"
}
}';
}
if (isset($_GET['carrer'])) {
$filters .= ',{"term" : { "terms.pointfinderltypes.term_id" : '.$_GET['carrer'].'}}';
}
if (isset($_GET['location'])) {
$filters .= ',{"term" : { "terms.pointfinderlocations.term_id" : '.$_GET['location'].'}}';
}
if (isset($_GET['size'])) {
$page='"size":'.$_GET['size'].',';
}
if (isset($_GET['from'])){$page .='"from":'.$_GET['from'].',';}
$query=json_decode('{'.$page.'"query": { "bool": { "must": ['.$search.'],"filter":['.$filters.']}},"sort": ['.$sort_by_coordinates.']}',true);
$params = [
"index" => "ypvn-post-1",
"body" => json_encode($query)
];
$response = $client->search($params);
print_r($response);
?>
PreviousTop 10 : Best autocomplete jQuery and javascript plugins (ok)NextTính khoảng cách khi biết tọa độ distance (ok)
Last updated