承接 shopwwi/webman-search 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shopwwi/webman-search

Composer 安装命令:

composer require shopwwi/webman-search

包简介

search for the webman

README 文档

README

'Build Status' 'Latest Stable Version' 'Total Downloads' 'License'

安装

composer require shopwwi/webman-search
  • 如果觉得方便了你 不要吝啬你的小星星哦 tycoonSong8988354@qq.com

使用方法

搜索选定器

  • xunsearch 使用讯搜搜索选定器
composer require hightman/xunsearch
  • meilisearch 使用meilisearch选定器
composer require meilisearch/meilisearch-php
  • elasticsearch 使用elasticsearch选定器(需8.0以上版本)
composer require elasticsearch/elasticsearch

搜索选定器服务端安装

搜索配置

  • 配置config/plugin/shopwwi/search/app.php 内配置 默认不需要配置

  • 生成密钥(如果生成了 启动meilisearch服务端的时候记得保持一致,其它搜索器不需要)

php webman shopwwi:search
  • 选定器调用(默认调用config设置的默认)
    use \Shopwwi\WebmanSearch\Facade\Search;
    // id为主键字段  index为索引
    $search = Search::use('meilisearch',['id'=>'id','index'=>'index']);
  • 执行命令方法
php webman search:create:index  // es搜索必须先执行此命令创建索引
php webman search:update:index  // 更新索引配置
php webman search:drop:index  //删除索引
  • 写入文档
      $data = [
        ['id' => 1, 'title' => '我从来都不曾承认我其实是个大帅哥' ,'create_at' => 2022-03-24 08:08:08,'type' => 'A'],
        ['id' => 2, 'title' => '时间万物除我之外' ,'create_at' => 2022-03-24 09:08:08,'type' => 'B'],
        ['id' => 3, 'title' => '你看见我的小熊了吗?' ,'create_at' => 2022-03-24 10:08:08,'type' => 'B'],
        ['id' => 4, 'title' => '这是一个神奇的世界,因为你永远不会知道我在哪' ,'create_at' => 2022-03-24 10:08:08,'type' => 'C']
      ]
    $search->create($data); //批量写入 支持单条 写入一维数组即可
  • 更新文档
      $data = [
        ['id' => 3, 'title' => '你看见我的小熊了吗?哈哈哈']
      ];
    $search->update($data);  // 批量修改 主键必须存在 单条修改写入一维数组
  • 删除文档
    $search->destroy(3);  //则会删除id为3的数据
    $search->destroy([2,3]); //批量删除 id为2和3的数据
  • 删除索引
    $search->clear();
  • 数据查询
    use \Shopwwi\WebmanSearch\Facade\Search;
    // 基础查询关键词
    $result = $search->q('')->get();
    // 全部查询 默认只显示20条
    $result = $search->get();
    //指定字段(默认指定所有)
    $result = $search->select(['id','title'])->get();
    //限定查询数量 默认为20
    $result = $search->limit(100)->q('')->get();
    //带条件搜索(一定要设定可检索字段 不然无效,一般在初始化新增之后)
    // where($column, $operator = null, $value = null, string $boolean = 'AND') static 搜索
    // orWhere($column, $operator = null, $value = null) static 搜索或者
    
    Search::updateFilterableAttributes(['id','title','type','create_at']);
    $result = $search->where('type','B')->limit(100)->q('')->get();
    $result = $search->where('type','!=','B')->limit(100)->q('')->get();
    $result = $search->orWhere('type','B')->limit(100)->q('')->get();
    // whereIn($column, $values, string $boolean = 'AND', bool $not = false) static 存在当中
    // orWhereIn(string $column, $values) static 搜索或者存在当然
    // whereNotIn(string $column,array $values, string $boolean = 'AND') static 搜索不存在当中
    // orWhereNotIn(string $column, $values) static 搜索或者不存在当中
    $result = $search->whereIn('type',['A','B'])->limit(100)->q('')->get();
    $result = $search->whereNotIn('type',['A','B'])->limit(100)->q('')->get();
    $result = $search->orWhereIn('type',['A','B'])->limit(100)->q('')->get();
    $result = $search->orWhereNotIn('type',['A','B'])->limit(100)->q('')->get();
    // whereRaw($sql,  $boolean = 'AND') static 原生数据查询
    $result = $search->where('type','B')->whereRaw('(id = 1 OR id = 2)')->limit(100)->q('')->get();
    //whereBetween($column,array $values, string $boolean = 'AND')
    $result = $search->whereBetween('id',[1,5])->limit(100)->q('')->get();
    //如果您的文档包含_geo数据,您可以使用_geoRadius内置过滤规则根据其地理位置过滤结果
    $result = $search->where('type','B')->whereRaw('_geoRadius(45.4628328, 9.1076931, 2000)')->limit(100)->q('')->get();
    
    // 分页
    $result = $search->where('type','B')->limit(20)->q('')->paginate(\request()->input('page',1));
    
    //关键词高亮
    $result = $search->where('type','B')->limit(20)->highlight(['title'])->q('')->paginate(\request()->input('page',1));
  • elasticSearch新升级whereRaw特定写法 支持query下的全部写法
    $search->whereRaw(['bool'=>['filter'=>[['term'=>['color'=>'red']],['term'=>['color'=>'blue']]]]]);
    $search->whereRaw(['bool'=>['must'=>[['term'=>['color'=>'red']],['term'=>['color'=>'blue']]]]]);
    // 如需使用aggs
    $result = $search->aggs(['avg_price'=>['avg'=>['field'=>'price']]])->q('华为')->get();
     // 获取原文返回内容
    $result->raw
  • 获取建议词(如搜索s则会出现与s相关的汉字数组 ,meilisearch不支持,es请使用原sdk方法查询)
    
    $result = $search->limit(20)->q('s')->suggest();// 不带统计数,数量都为0
    $result = $search->limit(20)->q('s')->suggest(true); // 带统计数
  • 获取指定文档
    $result = $search->first(2);
  • 字段排序
    // 字段排序(一定要设定可排序字段 不然无效,一般在初始化新增之后) 
    //1.使用orderBy方法
    $result = $search->where('type','B')->orderBy('create_at','desc')->orderBy('id')->limit(100)->q('')->get();
    //2.全局设定
    $result = $search->where('type','B')->limit(100)->q('')->get();
  • 获取原SDK方法(各方法请查看各选定器包说明文档)
   //返回所选定器本身SDK方法
    $search = Search::use('meilisearch',['id'=>'id','index'=>'index'])->us();

    //如meilisearch调用任务方法
    $search->getTasks(); // 查询所有任务

shopwwi/webman-search 适用场景与选型建议

shopwwi/webman-search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 411 次下载、GitHub Stars 达 20, 最近一次更新时间为 2022 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「meilisearch」 「webman」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 shopwwi/webman-search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shopwwi/webman-search 我们能提供哪些服务?
定制开发 / 二次开发

基于 shopwwi/webman-search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 411
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 0
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-30