From b8f2a9a7fbde41797996bae18d1920b32453e0b8 Mon Sep 17 00:00:00 2001 From: Logvinov Andrey Date: Wed, 29 Nov 2017 11:32:38 +0300 Subject: [PATCH 1/2] Add orWhere method. --- src/Query.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Query.php b/src/Query.php index 5fb0a1f..9b803fa 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 @@ -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; } From d8ef306ed81c7432271fc89d6eafd2da2618d8bd Mon Sep 17 00:00:00 2001 From: Logvinov Andrey Date: Wed, 29 Nov 2017 11:36:17 +0300 Subject: [PATCH 2/2] Fix isOperator. in_array(true,['=',...]) // true in_array(true,['=',...], true) // false --- src/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Query.php b/src/Query.php index 9b803fa..9d0fdfd 100755 --- a/src/Query.php +++ b/src/Query.php @@ -365,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; }