Skip to content

Commit

Permalink
add not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Sallam committed Jul 25, 2018
1 parent 82a48ec commit 9e9e2cd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Builders/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class QueryBuilder implements SearchInRangeContract, SearchContract
*/
protected $exist = [];

/**
* @var array $notExists
*/
protected $notExists = [];

/**
* @var array $whereTerms
*/
Expand Down Expand Up @@ -191,6 +196,18 @@ public function exist($attribute)
return $this;
}

/**
* add not exists constrains to the main filter
* @param $attribute
* @return $this
*/
public function notExists($attribute)
{
$this->notExists[] = $attribute;

return $this;
}

/**
* match words to field
* @param $attribute
Expand All @@ -216,6 +233,7 @@ public function resetBuilder()
$this->inRange = [];
$this->notInRange = [];
$this->exist = [];
$this->notExists = [];
$this->whereTerms = [];
$this->whereOr = [];
$this->match = [];
Expand Down Expand Up @@ -273,6 +291,11 @@ public function prepareQuery()
$this->prepareExistCondition($exist);
}

// add exists constrains to the query
foreach ($this->notExists as $notExists) {
$this->prepareNotExistsCondition($notExists);
}

// add matcher queries
foreach ($this->match as $match) {
$this->prepareMatchQueries($match);
Expand All @@ -293,6 +316,14 @@ private function prepareExistCondition($attribute)
$this->filter->addMust(new Exists($attribute));
}

/**
* Add not exists conditions to the main query
* @param $attribute
*/
private function prepareNotExistsCondition($attribute)
{
$this->filter->addMustNot(new Exists($attribute));
}

/**
* Add some bool terms to the main query
Expand Down

0 comments on commit 9e9e2cd

Please sign in to comment.