在 composer.json 文件中引入 elasticsearch-php:然后指定更新 composer update elasticsearch/elasticsearch

{"require":"elasticsearch/elasticsearch": "~6.0"}

创建索引

public function sou(){$client = ClientBuilder ::create()->setHosts(['127.0.0.1:9200'])->build();$params = ['index' => 'qxw','body' => ['settings'=>['number_of_shards'=>5, //分片数量(后期不可更改)'number_of_replicas'=>1 //副本数量(后期可更改)],'mappings'=>[
//                          'table'=>[
//                              'enabled'=>true //php版本7.0之后表名默认为‘_doc’,表名可以不加
//                        ],//加载ik分词器的字段'properties' => ['name' => ['type' => 'text','analyzer' => 'ik_max_word','search_analyzer' => 'ik_max_word'],'desc' => ['type' => 'text','analyzer' => 'ik_max_word','search_analyzer' => 'ik_max_word'],]],]];$response = $client->indices()->create($params);}

添加数据到数据库

 public function add(){$client = ClientBuilder::create()->build();$params = ['index' => 'qxw','type' => '_doc',//'id' => '1','body' => ['img' => "https://househomecdn.4fqp.com/storage/build/2021/02/21/202102211302369904.jpg",'name' => "半山洋房",'desc' => "安吉树兰健康谷售楼处树兰医院旁 小洋房",]];$response = $client->index($params);print_r($response);}

搜索

高亮搜索

public function showtime(Request $request){$title=$request->input('title');
//        $title="洋房";$client = ClientBuilder::create()->build();$params = ['index' => 'qxw',//'type' => '_doc','body' => ['query' => ['match' => ['name' => $title]],'highlight' => ['pre_tags' => ["<em style='color: lightcoral'>"],'post_tags' => ["</em>"],'fields' => ["name" => new \stdClass()]]]];$results = $client->search($params);
//       print_r($results['hits']['hits']);$arr=[];foreach ($results['hits']['hits'] as $k=>$v){
//            print_r($v);
//            $arr['name']=$v['highlight']['nane'][0];$arr[$k]['img']=$v['_source']['img'];$arr[$k]['name']=$v['highlight']['name'][0];$arr[$k]['desc']=$v['_source']['desc'];}// print_r($arr);return $arr;}

小程序端

xml

<view><form catchsubmit="formSubmit" catchreset="formReset"><input class="weui-input" name="title" placeholder="这是一个输入框" /><button style="margin: 30rpx 0" type="primary" formType="submit">搜索</button></form><block wx:for="{{str}}" wx:key='key'><view><rich-text nodes="{{item.title}}"></rich-text><text>{{item.content}}</text></view></block>

css


.a{width: 100%;height: 100px;
}.a-1{width: 40%;/* height: 100px; */float: left;
}
.a-1 image{width: 80px;height: 80px;
}
.a-2{width: 60%;height: 50px;float: right;
}

js

//高亮搜索formSubmit(e) {console.log(e);var _this = this;//console.log(e.detail.value.title)var title = e.detail.value.title;wx.request({url: 'http://localhost/index.php/api/showtime',data:{title:title},success:function(add){console.log(add.data)var fang = add.data;_this.setData({fang})}})},

微信小程序操作es简单搜索相关推荐

  1. 微信小程序操作教程(个人用户注册)

    一.注册账户 注册地址:https://mp.weixin.qq.com 1.邮箱注册 注意:每个邮箱只能注册一个小程序账户:邮箱即用户名 请记录用户名及密码 2.邮箱激活:点击链接激活账号 3.信息 ...

  2. android商品数量加减,微信小程序实现一个简单的商品数量加减案例

    简介 这是一个用微信小程序原生代码实现的数量加减demo,主要是用于商品购物车或者商品详情修改数量使用,很简单哦~~~. 核心js方法说明addCount(增加数量) delCount (减少数量) ...

  3. 微信小程序-006-投票功能-搜索投票

    微信小程序-006-投票功能-搜索投票-2020-8-16 目录 一.wxml 二.js pages/tools/vote/searchact/searchact 一.wxml <!--page ...

  4. 微信小程序操作图片放大、缩小、旋转、拖拽

    微信小程序操作图片放大.缩小.旋转.拖拽 在开发小程序的时候遇到了上传图片,然后编辑的需求.打算网上找一下相关代码组件的,就不用自己搞这么麻烦.经过一番折腾,还是没有找到如意的,最后自己弄好了,记录一 ...

  5. 微信小程序嵌套h5页面+发布微信小程序(超级简单)

    将发布的h5页面转换成微信小程序,无需重新开发,操作超级简单!!! 使用到的技术为uniapp和web-view 首先,我们先来了解一下web-view是什么: 简单的一句话来讲:web-view 是 ...

  6. 微信小程序之页面内搜索查询功能

    文章目录 一.效果演示 二.如何操作 三.项目demo地址 四.参考链接 一.效果演示 二.如何操作 具体操作可以参考博客原生微信小程序,搜索框(search)组件和微信小程序页面内搜索查询(无后台) ...

  7. 微信小程序前端备忘录记事本搜索功能

    微信小程序搜索功能,小程序自带weui, 阅读文档,WeUI组件库简介 | 微信开放文档 (qq.com) 1推荐使用方法: 在//app.json中录下下列句子 "useExtendedL ...

  8. 2020最新版前端学习路线图--微信小程序制作原来如此简单

    黑马程序员前端学习路线图大纲中第六阶段的学习是微信小程序的学习:主要介绍了前端学习路线图中微信小程序的学习目标,前端学习路线图中微信小程序的市场价值,前端学习路线图中微信小程序的重点知识.前端学习路线 ...

  9. 微信小程序--操作示例2

    微信小程序--商城首页 我们首先有一个商城的接口 调用商城中首页所需要的一些数据 例如: onLoad: function () {var that = this;//请求服务器时间戳wx.reque ...

最新文章

  1. HDU - 3987 Harry Potter and the Forbidden Forest(最小割最少边数)
  2. stanford-chinese-corenlp-yyyy-MM-dd-models.jar not exists解决
  3. freertos 创建互斥量_freertos任务通信
  4. 异步数据加载和Tab选项卡
  5. 互联网轻量级框架SSM-查缺补漏第九天
  6. mysql之配置使其可用python远程控制
  7. java跳跳球代码,README.md
  8. 点云数据集汇总整理(匠心之作,附官方下载地址)
  9. 中兴交换机8912E配置
  10. android 陀螺仪滤波_Savitzky-golay滤波在陀螺仪角加速度测量中的应用
  11. 现在学生物出路真有那么不济吗?(@Mengjie Chen)
  12. 关于Webgl实际中遇到的一些坑,与大家分享。
  13. MT6573芯片资料集锦芯片MTK6573_环境搭建
  14. codeigniter 使用
  15. 渗透之——Win10完美去除桌面快捷图标小箭头
  16. 红外焦平面阵列调试传递函数测试方法
  17. [转载]英语语音断句规则
  18. 在Gtalk中和你的msn,yahoo,icq/aim,qq好友聊天
  19. 使用Windows任务计划自动运行Python程序
  20. 【原】Linux shell script 21是什么意思

热门文章

  1. vscode中converting to execution character set: Illegal byte sequence
  2. Excel二维码图片生成器
  3. 使用scrapy爬取京东产品详细信息
  4. 云服务器怎么恢复初始设置
  5. 连续声纹识别 实时说话人分离
  6. BootStrap笔记-下拉菜单的使用
  7. Unity知识点总结(1)
  8. [原创]Win7SP1的映像DISM集成+kb3125574,打造Win7SP2
  9. FFmpeg滤镜:制作图片视频流(续2)
  10. RedHat7.8安装Microsoft Edge浏览器