Продолжение разработки поиска по представлениям

This commit is contained in:
RedHood 2021-01-24 16:35:24 +10:00
parent 3355611e20
commit 5faa656ede
2 changed files with 37 additions and 18 deletions

View File

@ -158,8 +158,4 @@ class ActiveQuery extends Query implements ActiveQueryInterface
return null;
}
}
public function view() {
}
}

View File

@ -103,7 +103,7 @@ class Query extends Component implements QueryInterface
*/
public function createCommand($db = null, $options = [])
{
list ($aql, $params) = $this->buildQuery($this);
list($aql, $params) = $this->buildQuery($this);
$options = ArrayHelper::merge(
$options,
@ -125,7 +125,7 @@ class Query extends Component implements QueryInterface
*/
public function execute($aql, $bindValues = [], $params = [])
{
list ($aql, $bindValues) = self::prepareBindVars($aql, $bindValues);
list($aql, $bindValues) = self::prepareBindVars($aql, $bindValues);
$options = [
'query' => $aql,
@ -197,7 +197,6 @@ class Query extends Component implements QueryInterface
}
return implode('.', $parts);
}
/**
@ -543,7 +542,7 @@ class Query extends Component implements QueryInterface
* @param $params
* @return string
*/
protected function buildSelect($columns, &$params)
protected function buildSelect($columns, &$params) // А нахуй здесь params ещё и ссылкой? Потом проверить
{
if ($columns === null || empty($columns)) {
return 'RETURN ' . $this->from;
@ -753,13 +752,15 @@ class Query extends Component implements QueryInterface
* @return bool
* @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);
$clauses = [
$this->buildFrom($collection),
$this->buildSearch($expression),
$this->buildSearch($expression, $type),
$this->buildLimit($this->limit, 0),
$this->buildOptions(),
$this->buildSelect($vars, $params)
];
$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');
throw new Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
}
$meta = $cursor->getMetadata();
return isset($meta['extra']['operations']['executed']) ?
$meta['extra']['operations']['executed'] :
true;
return $this->prepareResult($cursor->getAll());
}
/**
@ -864,9 +862,14 @@ class Query extends Component implements QueryInterface
* @param $columns
* @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;
}
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]].
* 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;
case 'BETWEEN':
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 [];
}
break;
@ -1301,5 +1322,7 @@ class Query extends Component implements QueryInterface
return $this;
}
public function emulateExecution ( $value = true ){}
public function emulateExecution($value = true)
{
}
}