You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.4 KiB
66 lines
1.4 KiB
<?php
|
|
error_reporting(0);
|
|
ini_set('display_errors', 0);
|
|
|
|
// nohup php /data1/www/zhishiku.kuailelunwen.com/tools/es_search.php &
|
|
include_once(dirname(dirname(__FILE__))."/vendor/autoload.php");
|
|
include_once(dirname(dirname(__FILE__))."/tools/es.php");
|
|
|
|
$data['status'] = false;
|
|
$data['info'] = '';
|
|
$data['data'] = [];
|
|
|
|
$obj = new \ES('weibo');
|
|
$from = 0;
|
|
$size = 25;
|
|
$keywords = $_POST['key'];
|
|
$token = $_POST['token'];
|
|
|
|
// $keywords = '发烧';
|
|
// $token = "ahckexb@!@#!@#$%cdasd%$";
|
|
|
|
if($token != "ahckexb@!@#!@#$%cdasd%$") {
|
|
echo 'succ';
|
|
exit;
|
|
}
|
|
|
|
if(empty($keywords)) {
|
|
$data['info'] = '错误';
|
|
echo json_encode($data, true);
|
|
exit;
|
|
}
|
|
|
|
$body = [
|
|
'query' => [
|
|
'bool' => [
|
|
'should' => [
|
|
[
|
|
'match' => [
|
|
'content' => [
|
|
'query' => $keywords,
|
|
'boost' => 4,
|
|
]
|
|
]
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'from' => $from,
|
|
'size' => $size
|
|
];
|
|
$res = $obj->search_doc('weibo', 'doc', $body);
|
|
$hits = $res['hits']['hits'];
|
|
if(empty($hits)){
|
|
$data['info'] = '数据为空';
|
|
echo json_encode($data, true);
|
|
exit;
|
|
}
|
|
|
|
$rdata = [];
|
|
foreach($hits as $val) {
|
|
$rdata[] = $val['_source'];
|
|
}
|
|
$data['status'] = true;
|
|
$data['data'] = $rdata;
|
|
echo json_encode($data, true);
|
|
exit;
|
|
|