zoukankan      html  css  js  c++  java
  • yii2.0 elasticsearch模糊查询

     最近使用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查询,后者没用过,用过再补上
    
    
  • 相关阅读:
    了解WP的传感器
    载入条LoadingBar
    能分组的GridView
    ASP.NET MVC的过滤器
    ASP.NET的路由
    自己绘制的仪表盘
    可拖拽的ListBox
    自己绘制的滑块条
    利用mciSendString播放音频
    mis导入器的加强版——vdproj文件资源浏览器
  • 原文地址:https://www.cnblogs.com/angellating/p/7146214.html
Copyright © 2011-2022 走看看