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.

75 lines
1.7 KiB

4 weeks ago
<?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,
]
]
],
// [
// 'match' => [
// 'abs' => [
// 'query' => $keywords,
// 'boost' => 3,
// ]
// ]
// ]
],
],
],
'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;