Продолжение разработки поиска по представлениям
This commit is contained in:
parent
3355611e20
commit
5faa656ede
|
@ -158,8 +158,4 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function view() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ class Query extends Component implements QueryInterface
|
||||||
*/
|
*/
|
||||||
public function createCommand($db = null, $options = [])
|
public function createCommand($db = null, $options = [])
|
||||||
{
|
{
|
||||||
list ($aql, $params) = $this->buildQuery($this);
|
list($aql, $params) = $this->buildQuery($this);
|
||||||
|
|
||||||
$options = ArrayHelper::merge(
|
$options = ArrayHelper::merge(
|
||||||
$options,
|
$options,
|
||||||
|
@ -125,7 +125,7 @@ class Query extends Component implements QueryInterface
|
||||||
*/
|
*/
|
||||||
public function execute($aql, $bindValues = [], $params = [])
|
public function execute($aql, $bindValues = [], $params = [])
|
||||||
{
|
{
|
||||||
list ($aql, $bindValues) = self::prepareBindVars($aql, $bindValues);
|
list($aql, $bindValues) = self::prepareBindVars($aql, $bindValues);
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'query' => $aql,
|
'query' => $aql,
|
||||||
|
@ -197,7 +197,6 @@ class Query extends Component implements QueryInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode('.', $parts);
|
return implode('.', $parts);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -543,7 +542,7 @@ class Query extends Component implements QueryInterface
|
||||||
* @param $params
|
* @param $params
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function buildSelect($columns, &$params)
|
protected function buildSelect($columns, &$params) // А нахуй здесь params ещё и ссылкой? Потом проверить
|
||||||
{
|
{
|
||||||
if ($columns === null || empty($columns)) {
|
if ($columns === null || empty($columns)) {
|
||||||
return 'RETURN ' . $this->from;
|
return 'RETURN ' . $this->from;
|
||||||
|
@ -753,13 +752,15 @@ class Query extends Component implements QueryInterface
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function search($collection, $expression, $params = [], $db = null)
|
public function search(string|array $collection, string|array $vars, array $expression, int $type = 0, $params = [], $db = null): array
|
||||||
{
|
{
|
||||||
$this->from($collection);
|
$this->from($collection);
|
||||||
$clauses = [
|
$clauses = [
|
||||||
$this->buildFrom($collection),
|
$this->buildFrom($collection),
|
||||||
$this->buildSearch($expression),
|
$this->buildSearch($expression, $type),
|
||||||
|
$this->buildLimit($this->limit, 0),
|
||||||
$this->buildOptions(),
|
$this->buildOptions(),
|
||||||
|
$this->buildSelect($vars, $params)
|
||||||
];
|
];
|
||||||
|
|
||||||
$aql = implode($this->separator, array_filter($clauses));
|
$aql = implode($this->separator, array_filter($clauses));
|
||||||
|
@ -787,10 +788,7 @@ class Query extends Component implements QueryInterface
|
||||||
Yii::endProfile($token, 'mirzaev\yii2\arangodb\Query::search');
|
Yii::endProfile($token, 'mirzaev\yii2\arangodb\Query::search');
|
||||||
throw new Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
|
throw new Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
|
||||||
}
|
}
|
||||||
$meta = $cursor->getMetadata();
|
return $this->prepareResult($cursor->getAll());
|
||||||
return isset($meta['extra']['operations']['executed']) ?
|
|
||||||
$meta['extra']['operations']['executed'] :
|
|
||||||
true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -864,9 +862,14 @@ class Query extends Component implements QueryInterface
|
||||||
* @param $columns
|
* @param $columns
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function buildSearch(string $expression,): string
|
protected function buildSearch(array $expression, int $type = 0): string
|
||||||
{
|
{
|
||||||
return 'SEARCH ' . Serializer::encode($expression);
|
$query = 'SEARCH ';
|
||||||
|
|
||||||
|
return match ($type) {
|
||||||
|
1 => $query . $this->filterStartsWith($expression),
|
||||||
|
default => $query . Serializer::encode($expression)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1035,6 +1038,23 @@ class Query extends Component implements QueryInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function filterStartsWith(array $expression): string
|
||||||
|
{
|
||||||
|
// Инициализация
|
||||||
|
$return = [];
|
||||||
|
|
||||||
|
// Генерация
|
||||||
|
foreach ($expression as $key => $value) {
|
||||||
|
if ($return) {
|
||||||
|
$return .= ' OR STARTS_WITH(' . $this->quoteCollectionName($this->from) . ".$key, \"$value\")";
|
||||||
|
} else {
|
||||||
|
$return = 'STARTS_WITH(' . $this->quoteCollectionName($this->from) . ".$key, \"$value\")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an additional WHERE condition to the existing one but ignores [[isEmpty()|empty operands]].
|
* Adds an additional WHERE condition to the existing one but ignores [[isEmpty()|empty operands]].
|
||||||
* The new condition and the existing one will be joined using the 'AND' operator.
|
* The new condition and the existing one will be joined using the 'AND' operator.
|
||||||
|
@ -1151,7 +1171,8 @@ class Query extends Component implements QueryInterface
|
||||||
break;
|
break;
|
||||||
case 'BETWEEN':
|
case 'BETWEEN':
|
||||||
if ((array_key_exists(1, $condition) && $this->isEmpty($condition[1]))
|
if ((array_key_exists(1, $condition) && $this->isEmpty($condition[1]))
|
||||||
|| (array_key_exists(2, $condition) && $this->isEmpty($condition[2]))) {
|
|| (array_key_exists(2, $condition) && $this->isEmpty($condition[2]))
|
||||||
|
) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1301,5 +1322,7 @@ class Query extends Component implements QueryInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emulateExecution ( $value = true ){}
|
public function emulateExecution($value = true)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue