Commit 6dd24bcc authored by clone's avatar clone

Merge branch 'search-test' into test

parents 12c37e34 40d585d9
...@@ -23,6 +23,7 @@ use app\model\Remarks; ...@@ -23,6 +23,7 @@ use app\model\Remarks;
use app\model\ULabels; use app\model\ULabels;
use app\model\UPhoneFollowUp; use app\model\UPhoneFollowUp;
use app\model\Users; use app\model\Users;
use app\search\service\SearchService;
class Remark extends Basic class Remark extends Basic
{ {
...@@ -77,50 +78,66 @@ class Remark extends Basic ...@@ -77,50 +78,66 @@ class Remark extends Basic
if (!empty($this->params['content'])) { if (!empty($this->params['content'])) {
$where['content'] = $this->params['content']; $where['content'] = $this->params['content'];
} }
if (!empty($this->params['remark_store_id'])) { // if (!empty($this->params['remark_store_id'])) {
$where['store_id'] = (int)$this->params['remark_store_id']; // $where['store_id'] = (int)$this->params['remark_store_id'];
} // }
if (!empty($this->params['remark_district_id'])) { // if (!empty($this->params['remark_district_id'])) {
$where['district_id'] = (int)$this->params['remark_district_id']; // $where['district_id'] = (int)$this->params['remark_district_id'];
} // }
//有权限的人可以查看其它城市的跟进 //有权限的人可以查看其它城市的跟进
if (!empty($this->params['site_id'])) { if (!empty($this->params['site_id'])) {
$site_id = $this->params['site_id']; $site_id = $this->params['site_id'];
} }
$if_search = false;
if ($this->siteId == "10001" && ($this->params['agent_id'] > 0 || !empty($this->params["content"])) && empty($this->params['user_id'])) {
$searchService = new SearchService();
$this->params['search_content'] = $this->params['content'];
$this->params['start_time'] = strtotime($this->params['start_date']);
$this->params['end_time'] = strtotime($this->params['end_date']);
$search_result = $searchService->searchByKeyword($this->params, $this->params['pageNo'], $this->params['pageSize'], $this->params['agent_id']);
$search_result = json_decode($search_result, true);
$result = $search_result["result"]["items"];
$if_search = true;
} else {
$follow_up_service = new PhoneFollowUpService($site_id);
$result_data = $follow_up_service->getPhoneFollowList($this->params['start_date'], $this->params['end_date'], $where, $this->userId);
if ($result_data['code'] == 200) {
$result = $result_data['data'];
} else {
$result = [];
}
}
if ($result) {
foreach ($result as $k => $v) {
if (!empty($v['user_id'])) {
$user_data = $m_user->getUserById('user_name,user_phone,vip,agent_id,create_time', $v['user_id']);
$list[$k]['user_name'] = $user_data['user_name'];
$list[$k]['user_phone'] = $user_data['user_phone'];
$list[$k]['u_create_time'] = $user_data['create_time'];
$list[$k]['vip'] = $user_data['vip'];
$list[$k]['agent_id'] = $user_data['agent_id']; //客户客方
}
$follow_up_service = new PhoneFollowUpService($site_id); $list[$k]['user_phone'] = substr_replace($list[$k]['user_phone'], '****', 3, 4);
$result_data = $follow_up_service->getPhoneFollowList($this->params['start_date'], $this->params['end_date'], $where, $this->userId); $list[$k]['admin'] = $m_agent->getAgentsById($v['agent_id'], 'name');
if ($result_data['code'] == 200) { $list[$k]['label_name'] = $v['label_name'];
if (!empty($result_data['data'])) { $list[$k]['is_outstrip_twenty_four_hours'] = $v['is_outstrip_twenty_four_hours'];
foreach ($result_data['data'] as $k => $v) { $list[$k]['is_outpace_call_num'] = $v['is_outpace_call_num'];
if (!empty($v['user_id'])) { $list[$k]['user_id'] = $v['user_id'];
$user_data = $m_user->getUserById('user_name,user_phone,vip,agent_id,create_time', $v['user_id']); $list[$k]['content'] = $v['content'];
$list[$k]['user_name'] = $user_data['user_name']; $list[$k]['user_status'] = $v['user_status'];
$list[$k]['user_phone'] = $user_data['user_phone']; $list[$k]['id'] = $v['id'];
$list[$k]['u_create_time'] = $user_data['create_time'];
$list[$k]['vip'] = $user_data['vip']; if ($if_search) {
$list[$k]['agent_id'] = $user_data['agent_id']; //客户客方 $list[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']/1000);
} } else {
$list[$k]['user_phone'] = substr_replace($list[$k]['user_phone'], '****', 3, 4);
$list[$k]['admin'] = $m_agent->getAgentsById($v['agent_id'], 'name');
$list[$k]['label_name'] = $v['label_name'];
$list[$k]['is_outstrip_twenty_four_hours'] = $v['is_outstrip_twenty_four_hours'];
$list[$k]['is_outpace_call_num'] = $v['is_outpace_call_num'];
$list[$k]['create_time'] = $v['create_time']; $list[$k]['create_time'] = $v['create_time'];
$list[$k]['user_id'] = $v['user_id'];
$list[$k]['content'] = $v['content'];
$list[$k]['user_status'] = $v['user_status'];
$list[$k]['id'] = $v['id'];
} }
} }
} else {
$msg = $result_data['data'];
$code = 101;
$list = [];
} }
$data['data']['list'] = $list; $data['data']['list'] = $list;
$data['data']['total'] = 40000; $data['data']['total'] = 40000;
return $this->response($code, $msg, $data); return $this->response($code, $msg, $data);
......
...@@ -1264,15 +1264,9 @@ class AAgents extends BaseModel ...@@ -1264,15 +1264,9 @@ class AAgents extends BaseModel
$result = Db::table($this->table) $result = Db::table($this->table)
->field($field) ->field($field)
->where($params) ->where($params)
->limit(1)
->select(); ->select();
if($result){ return $result;
$agentIds = "";
foreach ($result as $key1 => $value1) {
$agentIds .= $value1["id"] . ',';
}
$agentIds = rtrim($agentIds, ",");//经纪人ID集合
}
return $agentIds;
} }
......
...@@ -763,7 +763,7 @@ Route::group('broker', [ ...@@ -763,7 +763,7 @@ Route::group('broker', [
'setAgentLookNum' => ['api_broker/LookShop/setAgentLookNum', ['method' => 'post']], //设置经纪人的看铺数量 'setAgentLookNum' => ['api_broker/LookShop/setAgentLookNum', ['method' => 'post']], //设置经纪人的看铺数量
//首页跟进记录 //首页跟进记录
'userFollowUpList' => ['api_broker/HomePageLog/userFollowUpList', ['method' => 'post']], 'userFollowUpList' => ['api_broker/HomePageLog/userFollowUpList', ['method' => 'post|get']],
'userFollowUpListV2' => ['api_broker/HomePageLog/userFollowUpListV2', ['method' => 'post|get']], 'userFollowUpListV2' => ['api_broker/HomePageLog/userFollowUpListV2', ['method' => 'post|get']],
'houseFollowUpList' => ['api_broker/HomePageLog/houseFollowUpList', ['method' => 'post']], 'houseFollowUpList' => ['api_broker/HomePageLog/houseFollowUpList', ['method' => 'post']],
...@@ -877,4 +877,8 @@ Route::group('broker', [ ...@@ -877,4 +877,8 @@ Route::group('broker', [
]); ]);
Route::group('search', [
'search' => ['search/Search/search', ['method' => 'get|post']],
]);
//Route::miss('api/index/miss');//处理错误的url //Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
<?php
//配置文件
return [
];
\ No newline at end of file
<?php
namespace app\search\consts;
/**
* Created by PhpStorm.
* User : zw
* Date : 2019/1/9
* Time : 13:27
* Intro:
*/
class ConfigConst
{
const ACCESS_KEY_ID = "LTAIEeZUju3PFZlJ";
const SECRET = "ljKCItiUp19F7wtzfn225WoBH0Qe8Y";
const END_POINT = "http://opensearch-cn-shanghai.aliyuncs.com";//公网=>本地
//const END_POINT = "http://intranet.opensearch-cn-shanghai.aliyuncs.com";//内网==>线上
}
\ No newline at end of file
<?php
namespace app\search\controller;
class Index
{
public function index()
{
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>';
}
}
<?php
namespace app\search\controller;
use app\search\extend\Basic;
use app\search\service\SearchService;
use think\Request;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/4/10
* Time: 14:26
*/
class Search extends Basic {
private $service_;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->service_ = new SearchService();
}
public function search(){
$this->service_ ->search();
}
}
\ No newline at end of file
<?php
namespace app\search\extend;
use think\Cache;
use think\Controller;
use think\Request;
use think\Response;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/8
* Time : 16:54
* Intro:
*/
class Basic extends Controller
{
/**
* 访问请求对象
* @var Request
*/
public $request;
/**
* 请求参数
* @var mixed|null
*/
public $params;
/**
* app通讯接口授权token
* @var
*/
public $accessToken;
/**
* 基础接口SDK
* @param Request|null $request
*/
public function __construct(Request $request = null)
{
// CORS 跨域 Options 检测响应
$this->corsOptionsHandler();
// 输入对象
$this->request = is_null($request) ? Request::instance() : $request;
if (strtoupper($this->request->method()) === "GET") {
$this->params = $this->request->param();
} elseif (strtoupper($this->request->method()) === "POST") {
$this->params = $this->request->param() != null ? $this->request->param() : null;
}
}
/**
* 输出返回数据
* @param string $msg 提示消息内容
* @param string $code 业务状态码
* @param mixed $data 要返回的数据
* @param string $type 返回类型 JSON XML
* @return Response
*/
public function response($code = 'SUCCESS', $msg, $data = [], $type = 'json')
{
$result = [ 'code' => $code, 'msg' => $msg, 'data' => $data, 'type' => strtolower($type) ];
return Response::create($result, $type);
}
/**
* Cors Options 授权处理
*/
public static function corsOptionsHandler()
{
if (request()->isOptions()) {
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token');
header('Access-Control-Allow-Credentials:true');
header('Access-Control-Allow-Methods:GET,POST,OPTIONS');
header('Access-Control-Max-Age:1728000');
header('Content-Type:text/plain charset=UTF-8');
header('Content-Length: 0', true);
header('status: 204');
header('HTTP/1.0 204 No Content');
exit;
}
}
}
<?php
namespace app\search\service;
use app\search\consts\ConfigConst;
use OpenSearch\Client\OpenSearchClient;
use OpenSearch\Client\SearchClient;
use OpenSearch\Util\SearchParamsBuilder;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/4/10
* Time: 14:38
*/
require_once EXTEND_PATH . 'OpenSearch/Autoloader/Autoloader.php';
class SearchService
{
private $client;
public function __construct()
{
$options = array('debug' => true);
$this->client = new OpenSearchClient(ConfigConst::ACCESS_KEY_ID, ConfigConst::SECRET, ConfigConst::END_POINT, $options);
}
/**
* @param $params
* @param $page_no
* @param $page_size
* @param $agentId
* @return mixed|string
*/
public function searchByKeyword($params, $page_no, $page_size, $agentId)
{
$start_time = $params["start_time"] . "000";
$end_time = $params["end_time"] . "000";
$start_index = ($page_no - 1) * $page_size;
$searchClient = new SearchClient($this->client);
$condition = new SearchParamsBuilder();
$condition->setStart($start_index);
$condition->setHits($page_size);
$condition->setAppName("tl_estate");
$search_content = !empty($params["search_content"]) ? $params["search_content"] : null;
if ($search_content && $agentId <= 0) {
$condition->setQuery("content:'$search_content'");
} else if ($search_content && $agentId > 0) {
$condition->setQuery("content:'$search_content'");
$condition->setFilter("agent_id = '$agentId'");
} else if (!$search_content && $agentId > 0) {
$condition->setQuery("agent_id:'$agentId'");
}
$condition->addFilter("create_time > '$start_time'", " and create_time < '$end_time'");
$condition->setFormat("json");
$condition->addSort('id', SearchParamsBuilder::SORT_DECREASE);
$condition->setFetchFields(array('id', 'user_id', 'agent_id', 'type', 'content', 'create_time', 'city', 'user_status', 'labels_id'));
$ret = $searchClient->execute($condition->build())->result;
return $ret;
}
}
\ No newline at end of file
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
$basePath = __DIR__ . '/../../';
require_once $basePath . 'OpenSearch/Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', $basePath . 'OpenSearch');
$loader->registerNamespace('OpenSearch', $basePath);
$loader->registerDefinition('OpenSearch', $basePath);
$loader->register();
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace OpenSearch\Client;
use OpenSearch\Generated\App\AppServiceIf;
use OpenSearch\Generated\Common\Pageable;
/**
* 应用基本信息管理类。
*
* 管理应用的基本信息,包含创建应用(save)、修改应用(updateById)、删除应用(removeById)
* 、获取应用的基本详情(getById)、获取应用列表(listAll)、给应用导入全量数据(reindexById)
* 等方法。
*
*/
class AppClient implements AppServiceIf {
private $openSearchClient = null;
private $path = "/apps";
/**
* 构造方法。
*
* @param \OpenSearch\Client\OpenSearchClient $openSearchClient 基础类,负责计算签名,和服务端进行交互和返回结果。
* @return void
*/
public function __construct($openSearchClient) {
$this->openSearchClient = $openSearchClient;
}
/**
* 创建一个新应用,或者创建一个新版本。
*
* 创建一个新的应用或者创建一个新的版本,如果在$app中指定了name,则会创建一个新版本,否则会创建一个新应用。
*
* > 创建版本的个数依赖服务端的限制。
*
* @param string $app 要创建的应用主体JSON,包含name、type、schema、quota、first_ranks、second_ranks、summary、data_sources、suggest、fetch_fields、query_processors等信息。
* @return \OpenSearch\Generated\Common\OpenSearchResult OpenSearchResult类
*/
public function save($app) {
return $this->openSearchClient->post($this->path, $app);
}
/**
* 通过应用名称或者应用ID获取一个应用的详情信息。
*
* @param string $identity 要查询的应用名称或者应用ID,如果应用有多个版本,则指定应用名称为当前应用的在线版本。
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function getById($identity) {
$path = $this->path . "/" . $identity;
return $this->openSearchClient->get($path);
}
/**
* 获取应用列表。
*
* @param \OpenSearch\Generated\Common\Pageable $pageable 分页信息,包含页码和每页展示条数。
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function listAll(Pageable $pageable) {
return $this->openSearchClient->get(
$this->path, array('page' => $pageable->page, 'size' => $pageable->size)
);
}
/**
* 根据指定的应用id或名称删除应用版本或者应用;当指定的为应用名称,则表示指定的为当前应用分组中的在线的应用。。
*
* 如果当前应用只有一个版本,则会删除这个应用的整个分组;
* 如果当前应用分组有多个应用,则需要当前要删除的版本不能处于在线状态。
*
* @param string $identity 指定的应用ID或者应用名称。
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function removeById($identity) {
$path = $this->path . "/" . $identity;
return $this->openSearchClient->delete($path);
}
/**
* 更新某个应用的信息。
*
* @param string $identity 指定的应用ID或者应用名称;当指定的为应用名称,则表示指定的为当前应用分组中的在线的应用。
* @param string $app 修改一个应用的应用结构json,包含name、type、schema、quota、first_ranks、second_ranks、summary、data_sources、suggest、fetch_fields、query_processors等信息。
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function updateById($identity, $app) {
$path = $this->path . "/" . $identity;
return $this->openSearchClient->patch($path, $app);
}
/**
* 在创建过程中全量导入数据。
*
* @param string $identity 指定的应用ID或者应用名称;当指定的为应用名称,则表示指定的为当前应用分组中的在线的应用。。
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function reindexById($identity) {
$path = $this->path . "/{$identity}/actions/reindex";
return $this->openSearchClient->post($path);
}
}
\ No newline at end of file
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace OpenSearch\Client;
use OpenSearch\Generated\BehaviorCollection\Command;
use OpenSearch\Generated\BehaviorCollection\Constant;
use OpenSearch\Generated\BehaviorCollection\BehaviorCollectionServiceIf;
use OpenSearch\Client\OpenSearchClient;
/**
* 搜索行为数据文档推送类。
*
* 管理搜索应用的行为数据推送,包含单条推送文档、批量推送文档等。
*
*/
class BehaviorCollectionClient implements BehaviorCollectionServiceIf {
private $openSearchClient;
private $recordBuffer = array();
const SEARCH_DOC_CLICK_EVENT_ID = 2001;
/**
* 构造方法。
*
* @param \OpenSearch\Client\OpenSearchClient $openSearchClient 基础类,负责计算签名,和服务端进行交互和返回结果。
* @return void
*/
public function __construct($openSearchClient) {
$this->openSearchClient = $openSearchClient;
}
/**
* 增加一条搜索点击文档。
*
* > Note:
* >
* > 这条文档只是增加到sdk client buffer中,没有正式提交到服务端;只有调用了commit方法才会被提交到服务端。
* > 你可以多次addSearchDocClickRecord然后调用commit() 统一提交。
*
* @param string $searchDocListPage 搜索结果列表所在的页面名称
* @param string $docDetailPage 某个搜索文档被点击后,搜索文档的详情页面名称
* @param int $detailPageStayTime 用户在详情页停留的时长(单位为ms)
* @param string $objectId 被点击的文档的主键,不能为空
* @param string $opsRequestMisc opensearch返回的查询结果中的ops_request_misc字段
* @param string $basicFields 其他基础字段, 非必需字段
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function addSearchDocClickRecord(
$searchDocListPage,
$docDetailPage,
$detailPageStayTime,
$objectId,
$opsRequestMisc,
array $basicFields = []) {
$jsonFields = [
'event_id' => self::SEARCH_DOC_CLICK_EVENT_ID,
'sdk_type' => OpenSearchClient::SDK_TYPE,
'sdk_version' => OpenSearchClient::SDK_VERSION,
'page' => $docDetailPage,
'arg1' => $searchDocListPage,
'arg2' => "",
'arg3' => $detailPageStayTime,
'args' => self::createSearchDocClickArgs($objectId, $opsRequestMisc),
];
if (!empty($basicFields)) {
foreach ($basicFields as $key => $value) {
$jsonFields[$key] = $value;
}
}
$this->addOneRecord($jsonFields, Command::$__names[Command::ADD]);
}
/**
* 把sdk client buffer中的文档发布到服务端。
*
* > Note:
* >
* > 在发送之前会把buffer中的文档清空,所以如果服务端返回错误需要重试的情况下,需要重新生成文档并commit,避免丢数据的可能。
*
* @param string $searchAppName 关联的搜索应用名
* @param string $behaviorCollectionName 行为数据采集名称,开通时控制台会返回该名称
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function commit($searchAppName, $behaviorCollectionName) {
$recordsJson = json_encode($this->recordBuffer);
$this->recordBuffer = array();
return $this->doPush($recordsJson, $searchAppName, $behaviorCollectionName);
}
/**
* 批量推送文档。
*
* > Note:
* >
* > 此操作会同步发送文档到服务端。
*
* @param string $recordsJson 文档list的json
* @param string $searchAppName 关联的搜索应用名
* @param string $behaviorCollectionName 行为数据采集名称,开通时控制台会返回该名称
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function push($recordsJson, $searchAppName, $behaviorCollectionName) {
return $this->doPush($recordsJson, $searchAppName, $behaviorCollectionName);
}
private function doPush($recordsJson, $searchAppName, $behaviorCollectionName) {
$path = self::createPushPath($searchAppName, $behaviorCollectionName);
return $this->openSearchClient->post($path, $recordsJson);
}
private function addOneRecord($jsonFields, $command) {
$cmdName = Constant::get('DOC_KEY_CMD');
$fieldsName = Constant::get('DOC_KEY_FIELDS');
$jsonRecord = [
$cmdName => $command,
$fieldsName => $jsonFields
];
$this->recordBuffer[] = $jsonRecord;
}
private static function createPushPath($searchAppName, $behaviorCollectionName) {
return sprintf("/app-groups/%s/data-collections/%s/actions/bulk", $searchAppName, $behaviorCollectionName);
}
private static function createSearchDocClickArgs($objectId, $opsRequestMisc) {
return sprintf("object_id=%s,object_type=ops_search_doc,ops_request_misc=%s", $objectId, $opsRequestMisc);
}
}
\ No newline at end of file
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace OpenSearch\Client;
use OpenSearch\Generated\Document\Command;
use OpenSearch\Generated\Document\Constant;
use OpenSearch\Generated\Document\DocumentServiceIf;
/**
* 应用文档操作类。
*
* 管理应用的文档,包含推送文档,删除文档,更新文档,批量推送文档等。
*
*/
class DocumentClient implements DocumentServiceIf {
private $openSearchClient;
const DOCUMENT_API_PATH = '/apps';
/**
* @var sdk缓存的文档的数量。
*/
public $docs = array();
/**
* 构造方法。
*
* @param \OpenSearch\Client\OpenSearchClient $openSearchClient 基础类,负责计算签名,和服务端进行交互和返回结果。
* @return void
*/
public function __construct($openSearchClient) {
$this->openSearchClient = $openSearchClient;
}
/**
* 增加一条文档。
*
* > Note:
* >
* > 这条文档只是增加到sdk client buffer中,没有正式提交到服务端;只有调用了commit方法才会被提交到服务端。
* 你可以add多次然后调用commit() 统一提交。
*
* @param array $fields 一条文档的所有字段,例如array("id" => 1, "name" => "tony");
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function add($fields) {
$this->pushOneDoc($fields, Command::$__names[Command::ADD]);
}
/**
* 修改一条文档。
*
* > Note:
* >
* > 这条文档只是增加到sdk client buffer中,没有正式提交到服务端;只有调用了commit方法才会被提交到服务端。
* 你可以update多次然后调用commit() 统一提交。
*
* > 标准版不支持update操作。
*
* @param array $fields 一条文档的所有字段,例如array("id" => 1, "name" => "tony");
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function update($fields) {
$this->pushOneDoc($fields, Command::$__names[Command::UPDATE]);
}
/**
* 删除一条文档。
*
* > Note:
* >
* > 这条文档只是增加到sdk client buffer中,没有正式提交到服务端;只有调用了commit方法才会被提交到服务端。
* 你可以remove多次然后调用commit() 统一提交。
*
* @param array $fields 一条文档的主键字段,例如array("id" => 1);
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function remove($fields) {
$this->pushOneDoc($fields, Command::$__names[Command::DELETE]);
}
/**
* 批量推送文档。
*
* > Note:
* >
* > 此操作会同步发送到服务端。
*
* @param string $docsJson 文档list的json,例如[{"cmd":"ADD","fields":{"id":"1","name":"tony"}},...]
* @param string $appName 指定的app name或者app ID
* @param string $tableName 指定的table name
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function push($docsJson, $appName, $tableName) {
$path = self::_getPath($appName, $tableName);
return $this->openSearchClient->post($path, $docsJson);
}
/**
* 把client buffer中的文档发布到服务端。
*
* > Note:
* >
* > 在发送之前会把buffer中的文档清空,所以如果服务端返回错误需要重试的情况下,需要重新生成文档并commit,避免丢数据的可能。
*
* @param string $appName 指定的app name或者app ID
* @param string $tableName 指定的table name
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function commit($appName, $tableName) {
$json = json_encode($this->docs);
$this->docs = array();
return $this->push($json, $appName, $tableName);
}
/**
* 推送一条文档到客户端buffer中。
*
* @param array $fields 一条文档的所有字段,例如array("id" => 1, "name" => "tony");
* @param string $cmd 文档的操作类型,有ADD, UPDATE和DELETE;
* @return \OpenSearch\Generated\Common\OpenSearchResult
*/
public function pushOneDoc($fields, $cmd) {
$cmdName = Constant::get('DOC_KEY_CMD');
$fieldName = Constant::get('DOC_KEY_FIELDS');
$this->docs[] = array($cmdName => $cmd, $fieldName => $fields);
}
private static function _getPath($appName, $tableName) {
return self::DOCUMENT_API_PATH . sprintf("/%s/%s/actions/bulk", $appName, $tableName);
}
}
\ No newline at end of file
This diff is collapsed.
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace OpenSearch\Client;
use OpenSearch\Generated\Search\Config;
use OpenSearch\Generated\Search\OpenSearchSearcherServiceIf;
use OpenSearch\Generated\Search\SearchFormat;
use OpenSearch\Generated\Search\SearchParams;
use OpenSearch\Util\UrlParamsBuilder;
/**
* 应用搜索操作类。
*
* 通过制定关键词、过滤条件搜索应用结果。
*
*/
class SearchClient implements OpenSearchSearcherServiceIf {
const SEARCH_API_PATH = '/apps/%s/search';
private $openSearchClient;
/**
* 构造方法。
*
* @param \OpenSearch\Client\OpenSearchClient $openSearchClient 基础类,负责计算签名,和服务端进行交互和返回结果。
* @return void
*/
public function __construct($openSearchClient) {
$this->openSearchClient = $openSearchClient;
}
/**
* 执行搜索操作。
*
* @param \OpenSearch\Generated\Search\SearchParams $searchParams 制定的搜索条件。
* @return \OpenSearch\Generated\Common\OpenSearchResult OpenSearchResult类
*/
public function execute(SearchParams $searchParams) {
$path = self::getPath($searchParams);
$builder = new UrlParamsBuilder($searchParams);
return $this->openSearchClient->get($path, $builder->getHttpParams());
}
private static function getPath($searchParams) {
$appNames = isset($searchParams->config->appNames) ? implode(',', $searchParams->config->appNames) : '';
return sprintf(self::SEARCH_API_PATH, $appNames);
}
}
\ No newline at end of file
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace OpenSearch\Client;
use OpenSearch\Generated\Search\OpenSearchSearcherServiceIf;
use OpenSearch\Generated\Search\SearchParams;
use OpenSearch\Util\SuggestParamsBuilder;
/**
* 应用下拉提示操作类。
*
* 通过制定关键词、过滤条件搜索应用的下拉提示的结果。
*
*/
class SuggestClient implements OpenSearchSearcherServiceIf {
const SUGGEST_API_PATH = '/apps/%s/suggest/%s/search';
private $openSearchClient;
/**
* 构造方法。
*
* @param \OpenSearch\Client\OpenSearchClient $openSearchClient 基础类,负责计算签名,和服务端进行交互和返回结果。
* @return void
*/
public function __construct($openSearchClient) {
$this->openSearchClient = $openSearchClient;
}
/**
* 执行搜索操作。
*
* @param \OpenSearch\Generated\Search\SearchParams $searchParams 制定的搜索条件。
* @return \OpenSearch\Generated\Common\OpenSearchResult OpenSearchResult类
*/
public function execute(SearchParams $searchParams) {
$path = self::getPath($searchParams);
$params = SuggestParamsBuilder::getQueryParams($searchParams);
return $this->openSearchClient->get($path, $params);
}
private static function getPath($searchParams) {
$appName = implode(',', $searchParams->config->appNames);
$suggestName = $searchParams->suggest->suggestName;
return sprintf(self::SUGGEST_API_PATH, $appName, $suggestName);
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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