侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

hyperf+GuzzleHttp实现Meili Search搜索引擎文件的查增改删操作及数据库取出插入demo

swoole  /  管理员 发布于 1年前   1062

接上一篇索引的操作,这篇是文件的操作咯


文件

文档是由可以存储任何类型数据的字段组成的对象。

每个字段都包含一个属性及其关联的值。

文档存储在索引中。



环境跟上一篇一样

hyperf2.1

centos7+meilisearch


路由也一样

注解



控制器:

<?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/'
       ]);
   }

   
   /**
    * meilisearch搜索引擎  实现文件增删改查
    */
   public function mlsearch()
   {
       $client = new \GuzzleHttp\Client();

       //单查
       //curl -X GET 'http://localhost:7700/indexes/movies/documents/113965'
       //$resp = $client->request('GET', 'http://127.0.0.1:7700/indexes/movies/documents/113965');

       //批查  后面可带limit参数
       //curl -X GET 'http://localhost:7700/indexes/movies/documents?limit=2'
       $resp = $client->request('GET', 'http://127.0.0.1:7700/indexes/movies/documents');
       return json_decode((string) $resp->getBody(),true);

       //单删
       //curl -X DELETE 'http://localhost:7700/indexes/movies/documents/287947'
       //$resp = $client->delete('http://127.0.0.1:7700/indexes/movies/documents/287947');

       //批删
       //curl -X POST 'http://localhost:7700/indexes/movies/documents/delete-batch' --data '[113965,113729,113727,112134,113728]'
       /*$body = [113965,113729,113727,112134,113728];
       $resp = $client->request('POST', 'http://127.0.0.1:7700/indexes/movies/documents/delete-batch',
           [
               'headers' => ['content-type' => 'application/json;charset=UTF-8','accept' => 'application/ld+json'],
               'body' => json_encode($body),
           ]
       );
       */


       //增
       //curl -X POST 'http://localhost:7700/indexes/movies/documents' --data '[{"id":"3","title":"中国"},{"id":"4","title":"ddd"}]'
       /*$a = '[{"id":"3","title":"中国"},{"id":"4","title":"ddd"}]';
       $resp = $client->request('POST', 'http://127.0.0.1:7700/indexes/movies/documents',
           [
               'headers' => ['content-type' => 'application/json;charset=UTF-8','accept' => 'application/ld+json'],
               'body' => $a,
           ]
       );
       */

       //改
       //curl -X PUT 'http://localhost:7700/indexes/movies/documents' --data '[{"id": 3,"title": "中国广州"}]'
       /*$body = '[{"id": 3,"title": "中国广州"}]';
       $resp = $client->request('PUT', 'http://127.0.0.1:7700/indexes/movies/documents',
           [
               'headers' => ['content-type' => 'application/json', 'accept' => 'application/ld+json'],
               'body' => $body,
           ]
       );
       */


       //从数据库数取出据库               content
       $art = DB::table('art')->select(DB::raw('art_id as id'), 'title', 'pubtime', 'view', 'cat_id')
           ->where('is_state', 0)->where('is_del', 1)
           ->orderBy('art_id', 'desc')->limit(5)->get()->toJson();
       //把数据插入
       $resp = $client->request('POST', 'http://127.0.0.1:7700/indexes/movies/documents',
           [
               'headers' => ['content-type' => 'application/json;charset=UTF-8','accept' => 'application/ld+json'],
               'body' => $art,
           ]
       );

       return json_decode((string) $resp->getBody(),true);
   }

}


效果随便看看:


meili流水log

log.png


增

增.png


改

改.png


数据库取出插入

db插入.png




完








  • 上一条:
    hyperf+GuzzleHttp实现Meili Search搜索引擎索引的查增改删操作
    下一条:
    想要实现H5手机端在线浏览pdf文件功能,了解一下pdfh5.js插件
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在hyperf框架中使用基于protobuf的RPC生成器实现rpc服务(0个评论)
    • hyperf + 京东联盟sdk实现简单商品列表转链跳转购买商品功能示例(0个评论)
    • Hyperf 3.0版本发布(0个评论)
    • hyperf2.2框架中添加Cache代理类的流程步骤及使用案例(0个评论)
    • hyperf2.1框架使用Dockerfile部署流程步骤(0个评论)
    • 近期文章
    • 如何优雅处理async await错误推荐:await-to-js库(0个评论)
    • lodash工具库(0个评论)
    • 在Laravel项目中使用中间件方式统计用户在线时长功能代码示例(0个评论)
    • 在Laravel中构建业务流程模型(0个评论)
    • windows系统中安装FFMpeg及在phpstudy环境php7.3 + php-ffmpeg扩展的使用流程步骤(0个评论)
    • 在go语言中对浮点的数组、切片(slice)进行正向排序和反向排序(0个评论)
    • 在go语言中对整数数组、切片(slice)进行排序和反向排序(0个评论)
    • 在go语言中对字符串数组、切片(slice)进行排序和反向排序(0个评论)
    • 最新国内免注册ChatGPT体验站_ChatGPT镜像站访问链接地址2023/3/28持续更新(0个评论)
    • 在Laravel项目中的实现无密码认证之:发送邮箱链接授权(0个评论)
    • 近期评论
    • 博主 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..
    • xiaoB 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..
    • BUG4 在

      你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..
    • 博主 在

      go语言+beego框架中获取get,post请求的所有参数中评论 @ t1  直接在router.go文件中配就ok..
    • Jade 在

      如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
    • 2017-09
    • 2020-03
    • 2020-06
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-11
    • 2022-03
    • 2022-05
    • 2023-01
    • 2023-02
    • 2023-03
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客