Commit 2c0af2e3 authored by liuyuzhen's avatar liuyuzhen

Merge branch 'master_dev' of git.shenbd.com:qm-develop/shenbd into lyz

parents 41992ba2 a7c9ccb3
......@@ -11,6 +11,13 @@ class SearchController extends \Our\Controller_AbstractIndex {
$res=$serchService->createShopKeeperOrders();
$this->success($res);
}
public function createIkIndexAction()
{
$serchService=\Business\Search\SearchServiceModel::getInstance();
$res=$serchService->createShopKeeperIkOrders();
$this->success($res);
}
public function insertRowAction()
{
......@@ -18,6 +25,12 @@ class SearchController extends \Our\Controller_AbstractIndex {
$res=$serchService->insertRows();
$this->success($res);
}
public function searchAction()
{
$serchService=\Business\Search\SearchServiceModel::getInstance();
$res=$serchService->searchRows();
$this->success($res);
}
......
......@@ -11,7 +11,8 @@ class ApiConst
const randLengh = 8;
//10天数秒
const tenDaySecond = 864000;
// const tenDaySecond = 864000;
const tenDaySecond = 300;
//一天
const oneDaySecond = 86400;
//半天
......
......@@ -25,6 +25,22 @@ class SearchServiceModel extends \Business\AbstractModel
$res=$elasticsToolElasticssearch->createIndexDetail();
return $res;
}
public function createShopKeeperIkOrders()
{
$elasticsToolElasticssearch=\Elastics\ElasticsToolModel::getInstance('orders');
$delRes=$elasticsToolElasticssearch->deleteIndex();
$createRes=$elasticsToolElasticssearch->createIkField();
$postData=array(
['goodsName'=>""闺蜜"崔顺实被韩检方传唤 韩总统府促彻查真相"],
['goodsName'=>"韩举行"护国训练" 青瓦台:决不许国家安全出问题"],
['goodsName'=>"韩举行"护国训练" 青瓦台:决不许国家安全出问题"],
['goodsName'=>"媒体称FBI已经取得搜查令 检视希拉里电邮"],
['goodsName'=>"村上春树获安徒生奖 演讲中谈及欧洲排外问题"],
['goodsName'=>"希拉里团队炮轰FBI 参院民主党领袖批其“违法”"],
);
$res=$elasticsToolElasticssearch->postBulkDoc($postData);
return $res;
}
public function insertRows()
{
......@@ -38,6 +54,15 @@ class SearchServiceModel extends \Business\AbstractModel
return $res;
}
public function searchRows(){
$elasticsToolElasticssearch=\Elastics\ElasticsToolModel::getInstance('orders');
$query=array(
'goodsName'=>'希拉里和韩国',
);
$res=$elasticsToolElasticssearch->searchMatch($query);
return $res;
}
/**
* 类实例
......
......@@ -4,6 +4,7 @@ namespace Elastics;
use Elasticsearch\ClientBuilder;
use Error\CodeConfigModel;
use Error\ErrorModel;
use Our\ApiConst;
use Our\NameConst;
/**
......@@ -152,21 +153,26 @@ class ElasticsToolModel
$response = $this->client->update($updateParams);
}
public function search()
//一般传where就可以了,
public function searchMatch($where,$pageIndex=ApiConst::pageIndex,$pageSize=ApiConst::pageSize,$sort=array('_score' => array('order' => 'desc')))
{
$searchParams['index'] = 'my_index';
$searchParams['type'] = 'my_index';
$searchParams['from'] = 0;
$searchParams['size'] = 100;
$searchParams['sort'] = array(
'_score' => array(
'order' => 'desc'
)
$searchParams['index'] = $this->dbName;
$searchParams['type'] = $this->tbName;
$from=($pageIndex)*$pageSize;
$searchParams['from'] = $from;
$searchParams['size'] = $pageSize;
$searchParams['sort'] =$sort;
$searchParams['body']=array(
'query'=>array('match'=>$where),
);
// $searchParams['body']['query']['match']['testField'] = 'abc';
$retDoc = $this->client->search($searchParams);
print_r($retDoc);
if(!isset($retDoc['hits'])){
ErrorModel::throwException(CodeConfigModel::elasticsError);
}
$htis=$retDoc['hits']['hits'];
$returnData['list']=array_column($htis,'_source');
$returnData['total']=$retDoc['hits']['total'];
return $returnData;
}
public function getDocById($id)
......@@ -243,7 +249,21 @@ class ElasticsToolModel
$res = $this->client->index($params);
return $res;
}
//插入多条 Document:
public function postBulkDoc($rows){
foreach($rows as $row){
$params['body'][] = [
'index' => [
'_index' => $this->dbName,
'_type' => $this->tbName,
]
];
$params['body'][]=$row;
}
$res = $this->client->bulk($params);
return $res;
}
public function createIkField(){
$params = [
'index' => $this->dbName, //索引名称
......@@ -256,31 +276,16 @@ class ElasticsToolModel
]
)
),
'number_of_replicas' => 1 //主分片的副本数
],
'mappings' => [ //映射
'_default_' => [ //默认配置,每个类型缺省的配置使用默认配置
'_source' => [ // 存储原始文档
$this->tbName => [ //默认配置,每个类型缺省的配置使用默认配置
'dynamic' => [ // 存储原始文档
'enabled' => 'true'
],
'properties' => [ //配置数据结构与类型
'name' => [ //字段1
'type' => 'string',//类型 string、integer、float、double、boolean、date
'index' => 'analyzed',//索引是否精确值 analyzed not_analyzed
],
'age' => [ //字段2
'type' => 'integer',
],
'sex' => [ //字段3
'type' => 'string',
'index' => 'not_analyzed',
],
]
],
$this->tbName=> [
'properties' => [
'phone' => [
'type' => 'string',
'goodsName' => [ //字段1
"type" =>"string",
"analyzer"=> "ik_max_word"
],
]
],
......@@ -305,7 +310,7 @@ class ElasticsToolModel
]
]
];
$res = $this->es->indices()->putMapping($params);
$res = $this->client->indices()->putMapping($params);
return $res;
}
......@@ -318,7 +323,7 @@ class ElasticsToolModel
'query' => $query
]
];
$res = $this->es->search($params);
$res = $this->client->search($params);
return $res;
}
//查看mapping
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简单的html5 File测试 for pic2base64</title>
<style>
</style>
</head>
<body>
<form action="/search/createIkIndex" method="post">
用户登录状态key:<input name="data[key]" value="52da049f7e2fbf0e10da32dfe909850e"/><br />
<p id="img_area"></p>
<input type="submit" value="提交">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简单的html5 File测试 for pic2base64</title>
<style>
</style>
</head>
<body>
<form action="/search/search" method="post">
用户登录状态key:<input name="data[key]" value="52da049f7e2fbf0e10da32dfe909850e"/><br />
<p id="img_area"></p>
<input type="submit" value="提交">
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment