diff --git a/src/Query.php b/src/Query.php index 5fb0a1f..9d0fdfd 100755 --- a/src/Query.php +++ b/src/Query.php @@ -89,6 +89,9 @@ class Query */ public $must_not = []; + /** @var array $should Query bool should */ + protected $should = []; + /** * Query returned fields list * @var array @@ -362,7 +365,7 @@ public function orderBy($field, $direction = "asc") protected function isOperator($string) { - if (in_array($string, $this->operators)) { + if (in_array($string, $this->operators, true)) { return true; } @@ -601,6 +604,27 @@ public function whereNotIn($name, $value = []) return $this; } + /** + * Set the query or where in clause. + * + * @param $name + * @param array $value + * + * @return $this + */ + public function orWhere($name, $value = null) + { + if (is_callback_function($name)) { + $name($this); + + return $this; + } + + $this->should[] = ["term" => [$name => $value]]; + + return $this; + } + /** * Set the query where exists clause @@ -700,6 +724,11 @@ protected function getBody() $body["query"]["bool"]["must_not"] = $this->must_not; } + if (count($this->should)) { + $body["query"]["bool"]["should"] = $this->should; + $body["query"]["bool"]["minimum_should_match"] = 1; + } + if (count($this->filter)) { $body["query"]["bool"]["filter"] = $this->filter; }