public function build($query, $params = [])
{
$query = $query->prepare($this);
if (!empty($query->join)) {
throw new NotSupportedException('Build of "' . get_class($query) . '::join" is not supported.');
}
$params = empty($params) ? $query->params : array_merge($params, $query->params);
$from = $query->from;
if ($from === null && $query instanceof ActiveQuery) {
/* @var $modelClass ActiveRecord */
$modelClass = $query->modelClass;
$from = [$modelClass::indexName()];
}
$clauses = [$this->buildSelect($query->select, $params, $query->distinct, $query->selectOption), $this->buildFrom($from, $params), $this->buildWhere($from, $query->where, $params, $query->match), $this->buildGroupBy($query->groupBy, $query->groupLimit), $this->buildWithin($query->within), $this->buildHaving($query->from, $query->having, $params), $this->buildOrderBy($query->orderBy), $this->buildLimit($query->limit, $query->offset), $this->buildOption($query->options, $params), $this->buildFacets($query->facets, $params)];
$sql = implode($this->separator, array_filter($clauses));
$showMetaSql = $this->buildShowMeta($query->showMeta, $params);
if (!empty($showMetaSql)) {
$sql .= $this->querySeparator . $showMetaSql;
}
return [$sql, $params];
}