Query::filter() adjustments

This commit is contained in:
Alexander Makarov
2014-03-29 23:26:02 +04:00
parent a884c80fe3
commit 8cd247730a
7 changed files with 55 additions and 13 deletions

View File

@ -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;
}

View File

@ -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;