hyperf+GuzzleHttp实现Meili Search搜索引擎索引的查增改删操作
swoole  /  管理员 发布于 3年前   1483
上一篇文章是centos7中Meili Search搜索引擎安装,现在来测试一下索引增删改查的基操
环境
hyperf2.1
centos7+Meili Search搜索引擎
路由:
注解方式
控制器:
<?php
declare(strict_types=1);
namespace App\Controller;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\View\RenderInterface;
use Hyperf\Utils\ApplicationContext;
use Hyperf\DbConnection\Db;
use Hyperf\Guzzle\ClientFactory;
use Hyperf\HttpServer\Annotation\AutoController;
/**
* @AutoController()
*/
class TestController
{
/**
* @var \Hyperf\Guzzle\ClientFactory
*/
private $clientFactory;
public function __construct(ClientFactory $clientFactory)
{
$this->clientFactory = $clientFactory;
}
public function index(RenderInterface $render,ResponseInterface $response,RequestInterface $request)
{
//return $response->json('测试专用控制器');
return $response->json([
"errno"=>0,
"data" => '/upload/image/'
]);
}
public function meilisearch(RequestInterface $request,ResponseInterface $response)
{
$client = new \GuzzleHttp\Client();
//查询
// curl -X GET 'http://localhost:7700/indexes'
$resp = $client->request('GET', 'http://127.0.0.1:7700/indexes');
$a = $resp->getBody();
return $a;
//添加
//curl -X POST 'http://localhost:7700/indexes' --data '{"uid": "movies1","primaryKey": "movie_id1"}'
/*$body = [
"uid" => "movies2",
"primaryKey" => "movie_id2"
];
$resp = $client->request('POST', 'http://127.0.0.1:7700/indexes',
[
'headers' => [
'content-type' => 'application/json',
'accept' => 'application/ld+json'
],
'body' => json_encode($body),
]
);
return json_decode((string) $resp->getBody(),true);
*/
//修改
//curl -X PUT 'http://127.0.0.1:7700/indexes/movies2' --data '{"name" : "666"}'
/*$body = [
"name" => "666"
];
$resp = $client->request('PUT', 'http://127.0.0.1:7700/indexes/movies2',
[
'headers' => [
'content-type' => 'application/json',
'accept' => 'application/ld+json'
],
'body' => json_encode($body),
]
);
return json_decode((string) $resp->getBody(),true);
*/
//删除
//curl -X DELETE 'http://127.0.0.1:7700/indexes/movies1'
//$client->delete('http://127.0.0.1:7700/indexes/movies1');
//return 'test-Hyperf-meilisearch ';
}
}
截图比较麻烦,我就截一张有代表性的,Meili Search搜索引擎的操作日志看看:
在来一张
完
有兴趣的可以自行测试
官方文档:
https://docs.meilisearch.com/
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号