封装成 mdel
最后更新于:2022-04-02 04:01:58
[TOC]
## base.php
```
esClient = Di::getInstance()->get("ES");
}
/**
* searchByName
* @auth singwa
* @param [string] $name [description]
* @param [int] $from [description]
* @param [int] $size [description]
* @param string $type [description]
* @return [type] [description]
*/
public function searchByName($name, $from =0, $size = 10, $type = "match") {
$name = trim($name);
if(empty($name)) {
return [];
}
$params = [
"index" => $this->index,
"type" => $this->type,
'body' => [
'query' => [
$type => [
'name' => $name
],
],
'from' => $from,
'size' => $size
],
];
$result = $this->esClient->search($params);
return $result;
}
}
```
## 继承 base.php
```
namespace App\Model\Es;
class EsVideo extends EsBase {
public $index = "imooc_video";
public $type = "video";
}
```
';