douchen2025 2018-07-08 15:07
浏览 50
已采纳

在过滤器中包含“NULL”值以及Elastica中的范围过滤器

I'm using Elastica and I need to create the filter that will get NULL values along with values that lower than 100.

For now my code looks like this:

$this->filter = $qb->query()->bool();
$this->filter->addShould($qb->query()->range('price', ['lte' => 100]));

It returns data with price lower than 100. I also need to get data with null values. So far I tried:

$this->filter->addMustNot($qb->query()->exists('price')); // returns 0 items
$this->filter->addShould($qb->query()->missing('price')); // doesn't work. Gives undefined query "missing" in Facade.php

Could someone help me with this issue? Or how to fix the problem with undefined query "missing" or to create another filter that will fit my needs. Thanks.

  • 写回答

1条回答 默认 最新

  • duanchun1852 2018-07-08 16:04
    关注

    Used same range() to make it work how I need. So it looks like this:

    $this->filter->addMustNot($qb->query()->range('price', ['gte' => 100]));
    

    I'm using addMustNot so it filters all values that matches that filter (everything less than 100 will be returned, even if it's null value).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1