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).

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

报告相同问题?

悬赏问题

  • ¥15 把Excel导入MATLAB显示错误怎么解决?
  • ¥15 Java中消息和缓存如何使用
  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx