當(dāng)前位置:
首頁 >
yii2.0 elasticsearch模糊查询
發(fā)布時間:2025/3/20
30
豆豆
生活随笔
收集整理的這篇文章主要介紹了
yii2.0 elasticsearch模糊查询
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
最近使用yii2.0查詢es數(shù)據(jù),一般查找語句用的yii2.0的query類,遇到模糊查詢使用like的時候竟然報
like conditions are not supported by elasticsearch.在QueryBuilder.php中查找到這個函數(shù) private function buildLikeCondition($operator, $operands)
{
throw new NotSupportedException('like conditions are not supported by elasticsearch.');
}
修改此函數(shù)為: 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“應(yīng)該還可以用wildcards查詢,后者沒用過,用過再補上
轉(zhuǎn)載于:https://www.cnblogs.com/angellating/p/7146214.html
總結(jié)
以上是生活随笔為你收集整理的yii2.0 elasticsearch模糊查询的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python_day02 上节课知识点
- 下一篇: 面向对象设计原则之一:单一职责原则