Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
Arsen Mirzaev Tatyano-Muradovich | bbb53cca05 | ||
Arsen Mirzaev Tatyano-Muradovich | a14fb0709f | ||
Arsen Mirzaev Tatyano-Muradovich | df1f06ad80 |
|
@ -1,19 +1,19 @@
|
||||||
{
|
{
|
||||||
"name": "mirzaev/yii2-arangodb",
|
"name": "mirzaev/yii2-arangodb",
|
||||||
"description": "Library for connecting ArangoDB-PHP to Yii2",
|
"description": "Library for connecting ArangoDB to Yii2",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Yii2",
|
"Yii2",
|
||||||
"ArangoDB"
|
"ArangoDB"
|
||||||
],
|
],
|
||||||
"type": "yii2-extension",
|
"type": "yii2-extension",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "WTFPL",
|
||||||
"homepage": "https://git.hood.su/mirzaev/yii2/arangodb",
|
"homepage": "https://git.mirzaev.sexy/mirzaev/yii2-arangodb",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
||||||
"email": "red@hood.su",
|
"email": "arsen@mirzaev.sexy",
|
||||||
"homepage": "https://hood.su/mirzaev",
|
"homepage": "https://mirzaev.sexy",
|
||||||
"role": "Developer"
|
"role": "Programmer"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Ilya Rumyantsev",
|
"name": "Ilya Rumyantsev",
|
||||||
|
|
|
@ -74,24 +74,19 @@ class Query extends Component implements QueryInterface
|
||||||
*
|
*
|
||||||
* [свойство => его значение]
|
* [свойство => его значение]
|
||||||
*/
|
*/
|
||||||
public array $search;
|
public array|string $search;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тип поиска
|
* Фильтр
|
||||||
*/
|
|
||||||
public string $searchType = 'START';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Поиск
|
|
||||||
*
|
*
|
||||||
* [свойство => его значение]
|
* [свойство => его значение]
|
||||||
*/
|
*/
|
||||||
public array $filter;
|
public array|string $filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тип поиска
|
* Отладка
|
||||||
*/
|
*/
|
||||||
public string $filterType = 'START';
|
public bool $debug = false;
|
||||||
|
|
||||||
public $orderBy;
|
public $orderBy;
|
||||||
|
|
||||||
|
@ -157,6 +152,11 @@ class Query extends Component implements QueryInterface
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->debug) {
|
||||||
|
var_dump($aql);
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->getStatement($options, $db);
|
return $this->getStatement($options, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,20 +233,18 @@ class Query extends Component implements QueryInterface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public function search(array $text, string $type = 'START'): self
|
public function search(array|string $expressions): self
|
||||||
{
|
{
|
||||||
$this->search = $text;
|
$this->search = $expressions;
|
||||||
$this->searchType = $type;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public function filter(array $text, string $type = 'START'): self
|
public function filter(array|string $expressions): self
|
||||||
{
|
{
|
||||||
$this->filter = $text;
|
$this->filter = $expressions;
|
||||||
$this->filterType = $type;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -787,8 +785,13 @@ class Query extends Component implements QueryInterface
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
$orders = [];
|
$orders = [];
|
||||||
|
|
||||||
foreach ($columns as $name => $direction) {
|
foreach ($columns as $name => $direction) {
|
||||||
$orders[] = $this->quoteColumnName($name) . ($direction === SORT_DESC ? ' DESC' : '');
|
$orders[] = $this->quoteColumnName($name) . match($direction) {
|
||||||
|
SORT_DESC => ' DESC',
|
||||||
|
SORT_ASC => ' ASC',
|
||||||
|
default => ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'SORT ' . implode(', ', $orders);
|
return 'SORT ' . implode(', ', $orders);
|
||||||
|
@ -867,9 +870,9 @@ class Query extends Component implements QueryInterface
|
||||||
$query::genIn($query->in, $query->traversals),
|
$query::genIn($query->in, $query->traversals),
|
||||||
$query::genLet($query->lets),
|
$query::genLet($query->lets),
|
||||||
$query->genForeach($query->foreach),
|
$query->genForeach($query->foreach),
|
||||||
|
isset($query->search) ? $query->genSearch($query->search) : null,
|
||||||
|
isset($query->filter) ? $query->genFilter($query->filter) : null,
|
||||||
$query->genWhere($query->where, $params),
|
$query->genWhere($query->where, $params),
|
||||||
isset($query->search) ? $query->genSearch($query->search, $query->searchType) : null,
|
|
||||||
isset($query->filter) ? $query->genFilter($query->filter, $query->filterType) : null,
|
|
||||||
$query->genOrderBy($query->orderBy, $params),
|
$query->genOrderBy($query->orderBy, $params),
|
||||||
$query->genLimit($query->limit, $query->offset, $params),
|
$query->genLimit($query->limit, $query->offset, $params),
|
||||||
$query->genSelect($query->select, $params),
|
$query->genSelect($query->select, $params),
|
||||||
|
@ -877,6 +880,11 @@ class Query extends Component implements QueryInterface
|
||||||
|
|
||||||
$aql = implode($query->separator, array_filter($clauses));
|
$aql = implode($query->separator, array_filter($clauses));
|
||||||
|
|
||||||
|
if ($query->debug) {
|
||||||
|
var_dump($aql);
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
return self::prepareBindVars($aql, $params);
|
return self::prepareBindVars($aql, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -937,6 +945,7 @@ class Query extends Component implements QueryInterface
|
||||||
|
|
||||||
$statement = $this->createCommand($db);
|
$statement = $this->createCommand($db);
|
||||||
|
|
||||||
|
|
||||||
$token = $this->getRawAql($statement);
|
$token = $this->getRawAql($statement);
|
||||||
|
|
||||||
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
|
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
|
||||||
|
@ -1128,35 +1137,65 @@ class Query extends Component implements QueryInterface
|
||||||
* @param $columns
|
* @param $columns
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function genSearch(array $expression, string $type = 'START'): string
|
protected function genSearch(array|string $expressions): string
|
||||||
{
|
{
|
||||||
|
if (is_string($expressions)) return $expressions;
|
||||||
|
|
||||||
|
// Инициализация строки запроса
|
||||||
$query = 'SEARCH ';
|
$query = 'SEARCH ';
|
||||||
|
|
||||||
return match (strtoupper($type)) {
|
foreach ($expressions as $expression) {
|
||||||
'START', 'STARTS', 'STARTS_WITH' => $query . $this->filterStartsWith($expression),
|
// Перебор выражений
|
||||||
'START_SENSETIVE' => $query . $this->filterStartsWith($expression, sensetive: true),
|
|
||||||
'CONTAINS', 'LIKE' => $query . $this->filterContains($expression),
|
// Инициализация оператора
|
||||||
default => $query . Serializer::encode($expression)
|
$operator = isset($expression['operator']) ? ' ' . $expression['operator'] . ' ' : '';
|
||||||
|
|
||||||
|
// Генерация строки запроса
|
||||||
|
$query .= match (strtoupper($expression['type'])) {
|
||||||
|
'START', 'STARTS', 'STARTS_WITH' => $operator . $this->filterStartsWith($expression['condition']),
|
||||||
|
'START_SENSETIVE' => $operator . $this->filterStartsWith($expression['condition'], sensetive: true),
|
||||||
|
'CONTAINS', 'LIKE' => $operator . $this->filterContains($expression['condition']),
|
||||||
|
'LEVENSHTEIN' => $operator . $this->filterLevenshtein($expression['condition'], ...$expression['parameters']),
|
||||||
|
'PHRASE' => $operator . $this->filterPhrase($expression['condition'], ...$expression['parameters']),
|
||||||
|
default => $operator . Serializer::encode($expression['condition'])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $collection
|
* @param $collection
|
||||||
* @param $columns
|
* @param $columns
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function genFilter(array $expression, string $type = 'START'): string
|
protected function genFilter(array|string $expressions): string
|
||||||
{
|
{
|
||||||
|
if (isString($expressions)) return $expressions;
|
||||||
|
|
||||||
|
// Инициализация строки запроса
|
||||||
$query = 'FILTER ';
|
$query = 'FILTER ';
|
||||||
|
|
||||||
return match (strtoupper($type)) {
|
foreach ($expressions as $expression) {
|
||||||
'START', 'STARTS', 'STARTS_WITH' => $query . $this->filterStartsWith($expression),
|
// Перебор выражений
|
||||||
'START_SENSETIVE' => $query . $this->filterStartsWith($expression, sensetive: true),
|
|
||||||
'CONTAINS', 'LIKE' => $query . $this->filterContains($expression),
|
// Инициализация оператора
|
||||||
default => $query . Serializer::encode($expression)
|
$operator = isset($expression['operator']) ? ' ' . $expression['operator'] . ' ' : '';
|
||||||
|
|
||||||
|
// Генерация строки запроса
|
||||||
|
$query .= match (strtoupper($expression['type'])) {
|
||||||
|
'START', 'STARTS', 'STARTS_WITH' => $operator . $this->filterStartsWith($expression['condition']),
|
||||||
|
'START_SENSETIVE' => $operator . $this->filterStartsWith($expression['condition'], sensetive: true),
|
||||||
|
'CONTAINS', 'LIKE' => $operator . $this->filterContains($expression['condition']),
|
||||||
|
'LEVENSHTEIN' => $operator . $this->filterLevenshtein($expression['condition'], ...$expression['parameters']),
|
||||||
|
'PHRASE' => $operator . $this->filterPhrase($expression['condition'], ...$expression['parameters']),
|
||||||
|
default => $operator . Serializer::encode($expression['condition'])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Присвоение переменной значения
|
* Присвоение переменной значения
|
||||||
*
|
*
|
||||||
|
@ -1357,6 +1396,17 @@ class Query extends Component implements QueryInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $expression
|
||||||
|
*/
|
||||||
|
public function debug(bool $status = true)
|
||||||
|
{
|
||||||
|
$this->debug = $status;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public function let(string $name, mixed $value): static
|
public function let(string $name, mixed $value): static
|
||||||
|
@ -1483,6 +1533,44 @@ class Query extends Component implements QueryInterface
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function filterPhrase(array $expression, string $analyzer = 'text_en'): string
|
||||||
|
{
|
||||||
|
// Инициализация
|
||||||
|
$return = [];
|
||||||
|
|
||||||
|
foreach ($expression as $key => $value) {
|
||||||
|
// Перебор выражений
|
||||||
|
|
||||||
|
if ($return) {
|
||||||
|
$return .= ' OR PHRASE(' . $this->quoteCollectionName($this->collection) . ".$key, \"$value\", \"$analyzer\")";
|
||||||
|
} else {
|
||||||
|
$return = 'PHRASE(' . $this->quoteCollectionName($this->collection) . ".$key, \"$value\", \"$analyzer\")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function filterLevenshtein(array $expression, string $analyzer = 'text_en', int $distance = 3, bool $transpositions = true): string
|
||||||
|
{
|
||||||
|
// Инициализация
|
||||||
|
$return = [];
|
||||||
|
|
||||||
|
$transpositions = $transpositions ? 'true' : 'false';
|
||||||
|
|
||||||
|
foreach ($expression as $key => $value) {
|
||||||
|
// Перебор выражений
|
||||||
|
|
||||||
|
if ($return) {
|
||||||
|
$return .= ' OR ANALYZER(LEVENSHTEIN_MATCH(' . $this->quoteCollectionName($this->collection) . ".$key, \"$value\", $distance, $transpositions), \"$analyzer\")";
|
||||||
|
} else {
|
||||||
|
$return = 'ANALYZER(LEVENSHTEIN_MATCH(' . $this->quoteCollectionName($this->collection) . ".$key, \"$value\", $distance, $transpositions), \"$analyzer\")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
|
@ -1680,6 +1768,7 @@ class Query extends Component implements QueryInterface
|
||||||
$result[$column] = SORT_ASC;
|
$result[$column] = SORT_ASC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue