From ceb1318736e98e1f380514cb7d0998db4e0ec59d Mon Sep 17 00:00:00 2001 From: Shisun Xia Date: Tue, 13 Nov 2018 14:51:38 -0500 Subject: [PATCH] fixed a bug regarding to orWhere --- src/LaravelElasticsearchQueryBuilder.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/LaravelElasticsearchQueryBuilder.php b/src/LaravelElasticsearchQueryBuilder.php index 3c2c8c0..aa0f3a6 100644 --- a/src/LaravelElasticsearchQueryBuilder.php +++ b/src/LaravelElasticsearchQueryBuilder.php @@ -202,22 +202,14 @@ public function where($column, $operator = null, $value = null, $or = false, $bo break; case '!=': if($or) { - $builder = new LaravelElasticsearchQueryBuilder($this->model); - $builder->where($column, '!=', $value); - if(isset($this->query['bool']['should']['bool']) && $value !== null) { - $this->query['bool']['should']['bool']['must_not'][] = [(is_array($value) ? 'terms' : 'term') => [$column => $value]]; - } else if(isset($this->query['bool']['should']) && $value === null) { - $this->query['bool']['should'][] = ['exists' => ['field' => $column]]; + if($value === null) { + $this->query['bool']['should'][] = ['exists' => [ + 'field' => $column + ]]; } else { - if($value === null) { - $this->query['bool']['should'][] = ['exists' => [ - 'field' => $column - ]]; - } else { - $this->query['bool']['should']['bool'] = ['must_not' => [ - [(is_array($value) ? 'terms' : 'term') => [$column => $value]] - ]]; - } + $this->query['bool']['should'][] = ['bool' => ['must_not' => [ + [(is_array($value) ? 'terms' : 'term') => [$column => $value]] + ]]]; } } else { if($value === null) {