Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class Query
*/
public $must_not = [];

/** @var array $should Query bool should */
protected $should = [];

/**
* Query returned fields list
* @var array
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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]];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about match


return $this;
}


/**
* Set the query where exists clause
Expand Down Expand Up @@ -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;
}
Expand Down