mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-15 05:45:33 +08:00
Query::filter() adjustments
This commit is contained in:
@@ -92,7 +92,7 @@ class Query extends Component implements QueryInterface
|
||||
* @var array|string The filter part of this search query. This is an array or json string that follows the format of
|
||||
* the elasticsearch [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html).
|
||||
*/
|
||||
public $filter;
|
||||
public $filterPart;
|
||||
|
||||
public $facets = [];
|
||||
|
||||
@@ -459,9 +459,9 @@ class Query extends Component implements QueryInterface
|
||||
* @param string $filter
|
||||
* @return static the query object itself
|
||||
*/
|
||||
public function applyFilter($filter)
|
||||
public function filterPart($filter)
|
||||
{
|
||||
$this->filter = $filter;
|
||||
$this->filterPart = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -62,17 +62,17 @@ class QueryBuilder extends \yii\base\Object
|
||||
}
|
||||
|
||||
$whereFilter = $this->buildCondition($query->where);
|
||||
if (is_string($query->filter)) {
|
||||
if (is_string($query->filterPart)) {
|
||||
if (empty($whereFilter)) {
|
||||
$parts['filter'] = $query->filter;
|
||||
$parts['filter'] = $query->filterPart;
|
||||
} else {
|
||||
$parts['filter'] = '{"and": [' . $query->filter . ', ' . Json::encode($whereFilter) . ']}';
|
||||
$parts['filter'] = '{"and": [' . $query->filterPart . ', ' . Json::encode($whereFilter) . ']}';
|
||||
}
|
||||
} elseif ($query->filter !== null) {
|
||||
} elseif ($query->filterPart !== null) {
|
||||
if (empty($whereFilter)) {
|
||||
$parts['filter'] = $query->filter;
|
||||
$parts['filter'] = $query->filterPart;
|
||||
} else {
|
||||
$parts['filter'] = ['and' => [$query->filter, $whereFilter]];
|
||||
$parts['filter'] = ['and' => [$query->filterPart, $whereFilter]];
|
||||
}
|
||||
} elseif (!empty($whereFilter)) {
|
||||
$parts['filter'] = $whereFilter;
|
||||
|
||||
@@ -819,6 +819,16 @@ class Query extends Component implements QueryInterface
|
||||
$operator = strtoupper($condition[0]);
|
||||
|
||||
switch ($operator) {
|
||||
case 'NOT':
|
||||
case 'AND':
|
||||
case 'OR':
|
||||
$subCondition = $this->filterCondition($condition[1]);
|
||||
if ($this->parameterNotEmpty($subCondition)) {
|
||||
$condition[1] = $subCondition;
|
||||
} else {
|
||||
$condition = [];
|
||||
}
|
||||
break;
|
||||
case 'IN':
|
||||
case 'NOT IN':
|
||||
case 'LIKE':
|
||||
@@ -837,7 +847,7 @@ class Query extends Component implements QueryInterface
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$condition = $this->filterConditionHash($condition);
|
||||
$condition = $this->filterHashCondition($condition);
|
||||
}
|
||||
return $condition;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user