yii2.0 elasticsearch模糊查询
2017-07-10 15:54
423 查看
最近使用yii2.0查询es数据,一般查找语句用的yii2.0的query类,遇到模糊查询使用like的时候竟然报
like conditions are not supported by elasticsearch. 在QueryBuilder.php中查找到这个函数
private function buildLikeCondition($operator, $operands) { throw new NotSupportedException('like conditions are not supported by elasticsearch.'); } 修改此函数为:
private function buildLikeCondition($operator, $operands) { if (!isset($operands[0], $operands[1])) { throw new InvalidParamException("Operator '$operator' requires two operands."); } if($operator=="like"){ return [ 'regexp' => [ $operands[0]=>".*".$operands[1].".*", ], ]; }else{ throw new NotSupportedException('like conditions are not supported by elasticsearch.'); } } 解决了like模糊查询,用到了正则匹配语句。暂时解决了项目模糊查询的需要。用正则”regexp“应该还可以用wildcards查询,后者没用过,用过再补上
相关文章推荐
- yii2.0 查询elasticsearch常用语句
- Yii2.0中文开发向导——查询条件Where全解析
- Yii 2.0实现联表查询加搜索分页的方法示例
- Yii2.0 对数据库 查询的一些简单的操作
- yii2.0 mongodb 模糊查询
- ElasticSearch 模糊匹配查询
- YII2.0 常用查询语句
- Yii2.0框架基础--数据查询之AR类方法一
- Yii2.0 数据库查询
- Yii2.0框架基础--数据查询之AR类方法where()
- Yii2.0 AR查询 报错“”has no relation named“”
- YII2.0 查询生成器-数据库访问
- Elasticsearch源码分析五--调用Lucene查询接口之模糊查询(Fuzzy)
- Elasticsearch5.3 学习(一):安装、Yii2.0 下载es扩展
- Yii2.0框架基础--数据查询之AR类方法 关联查询
- Elasticsearch中同时实现对某一字段的精确查询和模糊查询的方法
- Yii2.0-advanced-6—联表查询加搜索分页
- Yii2.0中文开发向导——查询条件Where全解析
- ElasticSearch封装查询、多条件查询、模糊查询工具类
- Yii2.0-advanced-10—数据库操作2(查询构建器)