From 5faa656ede7b29a46393cc5703d23bf843a26416 Mon Sep 17 00:00:00 2001 From: RedHood Date: Sun, 24 Jan 2021 16:35:24 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B7=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B8=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mirzaev/yii2-arangodb/ActiveQuery.php | 4 --- mirzaev/yii2-arangodb/Query.php | 51 +++++++++++++++++++-------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/mirzaev/yii2-arangodb/ActiveQuery.php b/mirzaev/yii2-arangodb/ActiveQuery.php index 5e21793..3d27e28 100644 --- a/mirzaev/yii2-arangodb/ActiveQuery.php +++ b/mirzaev/yii2-arangodb/ActiveQuery.php @@ -158,8 +158,4 @@ class ActiveQuery extends Query implements ActiveQueryInterface return null; } } - - public function view() { - - } } diff --git a/mirzaev/yii2-arangodb/Query.php b/mirzaev/yii2-arangodb/Query.php index fa0da7c..4e52373 100644 --- a/mirzaev/yii2-arangodb/Query.php +++ b/mirzaev/yii2-arangodb/Query.php @@ -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) + { + } }