|
@@ -7,19 +7,6 @@ require dirname(__FILE__) . '/pdo.php';
|
|
|
|
|
|
|
|
class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
|
{
|
|
{
|
|
|
- private $pdo = null;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Create a new instance.
|
|
|
|
|
- *
|
|
|
|
|
- * @return void
|
|
|
|
|
- */
|
|
|
|
|
- public function __construct()
|
|
|
|
|
- {
|
|
|
|
|
- $this->pdo = new PdoHelper;
|
|
|
|
|
- $this->pdo->connectDb();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public function Pali(
|
|
public function Pali(
|
|
|
\Mint\Tulip\V1\SearchRequest $request,
|
|
\Mint\Tulip\V1\SearchRequest $request,
|
|
|
\Grpc\ServerContext $context
|
|
\Grpc\ServerContext $context
|
|
@@ -30,6 +17,8 @@ class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
|
}
|
|
}
|
|
|
echo "[".date("Y/m/d h:i:sa") ."] pali search: request words = ".implode(',',$keyWords) .PHP_EOL;
|
|
echo "[".date("Y/m/d h:i:sa") ."] pali search: request words = ".implode(',',$keyWords) .PHP_EOL;
|
|
|
|
|
|
|
|
|
|
+ $pdo = new PdoHelper;
|
|
|
|
|
+ $pdo->connectDb();
|
|
|
/**
|
|
/**
|
|
|
* 查询业务逻辑
|
|
* 查询业务逻辑
|
|
|
*/
|
|
*/
|
|
@@ -97,16 +86,13 @@ class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
|
$querySelect_2 = " book,paragraph,content ";
|
|
$querySelect_2 = " book,paragraph,content ";
|
|
|
|
|
|
|
|
$queryCount = "SELECT count(*) as co FROM fts_texts WHERE {$queryWhere} {$queryBookId};";
|
|
$queryCount = "SELECT count(*) as co FROM fts_texts WHERE {$queryWhere} {$queryBookId};";
|
|
|
- $resultCount = $this->pdo->dbSelect($queryCount, $_queryWhere['param']);
|
|
|
|
|
- if(!$resultCount){
|
|
|
|
|
- logger('error','select fail.'.$this->pdo->errorInfo());
|
|
|
|
|
- $total = 0;
|
|
|
|
|
- }else if(is_array($resultCount) &&
|
|
|
|
|
|
|
+ $resultCount = $pdo->dbSelect($queryCount, $_queryWhere['param']);
|
|
|
|
|
+ if(is_array($resultCount) &&
|
|
|
count($resultCount)>0 &&
|
|
count($resultCount)>0 &&
|
|
|
isset($resultCount[0]['co'])){
|
|
isset($resultCount[0]['co'])){
|
|
|
$total = $resultCount[0]['co'];
|
|
$total = $resultCount[0]['co'];
|
|
|
}else{
|
|
}else{
|
|
|
- logger('warning','result must be of type array'.$this->pdo->errorInfo());
|
|
|
|
|
|
|
+ logger('warning','result must be of type array'.$pdo->errorInfo());
|
|
|
$total = 0;
|
|
$total = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -142,7 +128,7 @@ class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
|
$param[] = $limit;
|
|
$param[] = $limit;
|
|
|
$param[] = $offset;
|
|
$param[] = $offset;
|
|
|
|
|
|
|
|
- $result = $this->pdo->dbSelect($query, $param);
|
|
|
|
|
|
|
+ $result = $pdo->dbSelect($query, $param);
|
|
|
//返回数据
|
|
//返回数据
|
|
|
$response = new \Mint\Tulip\V1\SearchResponse();
|
|
$response = new \Mint\Tulip\V1\SearchResponse();
|
|
|
$output = $response->getItems();
|
|
$output = $response->getItems();
|
|
@@ -182,6 +168,8 @@ class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
|
/**
|
|
/**
|
|
|
* 查询业务逻辑
|
|
* 查询业务逻辑
|
|
|
*/
|
|
*/
|
|
|
|
|
+ $pdo = new PdoHelper;
|
|
|
|
|
+ $pdo->connectDb();
|
|
|
|
|
|
|
|
$searchChapters = [];
|
|
$searchChapters = [];
|
|
|
$searchBooks = [];
|
|
$searchBooks = [];
|
|
@@ -201,7 +189,7 @@ class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
|
echo 'query mode = '.$matchMode.PHP_EOL;
|
|
echo 'query mode = '.$matchMode.PHP_EOL;
|
|
|
$queryWhere = $this->makeQueryWhere($keyWords,$matchMode);
|
|
$queryWhere = $this->makeQueryWhere($keyWords,$matchMode);
|
|
|
$query = "SELECT pcd_book_id, count(*) as co FROM fts_texts WHERE {$queryWhere['query']} {$queryBookId} GROUP BY pcd_book_id ORDER BY co DESC;";
|
|
$query = "SELECT pcd_book_id, count(*) as co FROM fts_texts WHERE {$queryWhere['query']} {$queryBookId} GROUP BY pcd_book_id ORDER BY co DESC;";
|
|
|
- $result = $this->pdo->dbSelect($query, $queryWhere['param']);
|
|
|
|
|
|
|
+ $result = $pdo->dbSelect($query, $queryWhere['param']);
|
|
|
//返回数据
|
|
//返回数据
|
|
|
$response = new \Mint\Tulip\V1\BookListResponse();
|
|
$response = new \Mint\Tulip\V1\BookListResponse();
|
|
|
$output = $response->getItems();
|
|
$output = $response->getItems();
|
|
@@ -217,117 +205,7 @@ class Greeter extends \Mint\Tulip\V1\SearchStub
|
|
|
echo "total=".count($output).PHP_EOL;
|
|
echo "total=".count($output).PHP_EOL;
|
|
|
return $response;
|
|
return $response;
|
|
|
}
|
|
}
|
|
|
- /**
|
|
|
|
|
- * @param \Mint\Tulip\V1\UploadDictionaryRequest $request client request
|
|
|
|
|
- * @param \Grpc\ServerContext $context server request context
|
|
|
|
|
- * @return \Mint\Tulip\V1\UploadDictionaryResponse for response data, null if if error occured
|
|
|
|
|
- * initial metadata (if any) and status (if not ok) should be set to $context
|
|
|
|
|
- */
|
|
|
|
|
- public function UploadDictionary(
|
|
|
|
|
- \Mint\Tulip\V1\UploadDictionaryRequest $request,
|
|
|
|
|
- \Grpc\ServerContext $context
|
|
|
|
|
- ): ?\Mint\Tulip\V1\UploadDictionaryResponse {
|
|
|
|
|
- $response = new \Mint\Tulip\V1\UploadDictionaryResponse();
|
|
|
|
|
- $data = $request->getData();
|
|
|
|
|
- logger('debug',"received data size=".strlen($data));
|
|
|
|
|
- $dir = dirname(__FILE__) . '/storage';
|
|
|
|
|
- if(!is_dir($dir)){
|
|
|
|
|
- $res = mkdir($dir,0700,true);
|
|
|
|
|
- if(!$res){
|
|
|
|
|
- logger('error',"mkdir fail path=".$dir);
|
|
|
|
|
- $response->setError(1);
|
|
|
|
|
- return $response;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- $filename = $dir.'/pali-'.date("Y-m-d-h-i-sa").'.syn';
|
|
|
|
|
- $size = file_put_contents($filename,$data);
|
|
|
|
|
|
|
|
|
|
- if($size === false){
|
|
|
|
|
- logger('error',"file write fail ");
|
|
|
|
|
- $response->setError(1);
|
|
|
|
|
- return $response;
|
|
|
|
|
- }
|
|
|
|
|
- logger('debug',"save file size={$size} ");
|
|
|
|
|
- $response->setError(0);
|
|
|
|
|
- return $response;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function Update(
|
|
|
|
|
- \Mint\Tulip\V1\UpdateRequest $request,
|
|
|
|
|
- \Grpc\ServerContext $context
|
|
|
|
|
- ): ?\Mint\Tulip\V1\UpdateResponse {
|
|
|
|
|
- $response = new \Mint\Tulip\V1\UpdateResponse();
|
|
|
|
|
- $book = $request->getBook();
|
|
|
|
|
- $paragraph = $request->getParagraph();
|
|
|
|
|
- logger('debug',"update start book={$book} para={$paragraph} ");
|
|
|
|
|
- $now = date("Y-m-d H:i:s");
|
|
|
|
|
- //查询是否存在
|
|
|
|
|
- $query = 'SELECT id from fts_texts where book=? and paragraph = ?';
|
|
|
|
|
- $result = $this->pdo->dbSelect($query, [$book,$paragraph]);
|
|
|
|
|
- if(count($result) >0 ){
|
|
|
|
|
- //存在 update
|
|
|
|
|
- $query = 'UPDATE fts_texts set
|
|
|
|
|
- "bold_single"=?,
|
|
|
|
|
- "bold_double"=?,
|
|
|
|
|
- "bold_multiple"=?,
|
|
|
|
|
- "content"=?,
|
|
|
|
|
- "pcd_book_id"=?,
|
|
|
|
|
- "updated_at"=? where id=? ';
|
|
|
|
|
- $update = $this->pdo->dbSelect($query, [
|
|
|
|
|
- $request->getBold1(),
|
|
|
|
|
- $request->getBold2(),
|
|
|
|
|
- $request->getBold3(),
|
|
|
|
|
- $request->getContent(),
|
|
|
|
|
- $request->getPcdBookId(),
|
|
|
|
|
- $now,
|
|
|
|
|
- $result[0]['id']
|
|
|
|
|
- ]);
|
|
|
|
|
- }else{
|
|
|
|
|
- // new
|
|
|
|
|
- $query = "INSERT INTO fts_texts (
|
|
|
|
|
- book,
|
|
|
|
|
- paragraph,
|
|
|
|
|
- bold_single,
|
|
|
|
|
- bold_double,
|
|
|
|
|
- bold_multiple,
|
|
|
|
|
- \"content\",
|
|
|
|
|
- created_at,
|
|
|
|
|
- updated_at,
|
|
|
|
|
- pcd_book_id) VALUES
|
|
|
|
|
- (?,?,?,?,?,?,?,?,? )";
|
|
|
|
|
- $insert = $this->pdo->dbSelect($query, [
|
|
|
|
|
- $request->getBook(),
|
|
|
|
|
- $request->getParagraph(),
|
|
|
|
|
- $request->getBold1(),
|
|
|
|
|
- $request->getBold2(),
|
|
|
|
|
- $request->getBold3(),
|
|
|
|
|
- $request->getContent(),
|
|
|
|
|
- $now,
|
|
|
|
|
- $now,
|
|
|
|
|
- $request->getPcdBookId(),
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $response->setCount(0);
|
|
|
|
|
- return $response;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private function _updateIndex($book,$para){
|
|
|
|
|
- $query = 'UPDATE fts_texts SET content = content,
|
|
|
|
|
- bold_single = bold_single,
|
|
|
|
|
- bold_double = bold_double,
|
|
|
|
|
- bold_multiple = bold_multiple
|
|
|
|
|
- WHERE book = ? AND paragraph = ?';
|
|
|
|
|
- $update = $this->pdo->dbSelect($query, [$book,$para]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private function _updateIndexAll(){
|
|
|
|
|
- $query = 'UPDATE fts_texts SET content = content,
|
|
|
|
|
- bold_single = bold_single,
|
|
|
|
|
- bold_double = bold_double,
|
|
|
|
|
- bold_multiple = bold_multiple';
|
|
|
|
|
- $update = $this->pdo->dbSelect($query);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
private function makeQueryWhere($key,$match){
|
|
private function makeQueryWhere($key,$match){
|
|
|
$param = [];
|
|
$param = [];
|