diff --git a/src/Elasticsearch/Objects/Documents.php b/src/Elasticsearch/Objects/Documents.php index 0793ab2d..f905eb34 100644 --- a/src/Elasticsearch/Objects/Documents.php +++ b/src/Elasticsearch/Objects/Documents.php @@ -232,6 +232,8 @@ public static function getById($id) : self /** * Find by query in this document. * + * @todo add findFirst and Find() like phalcon + * * @param string $sql * * @return array diff --git a/src/Http/QueryParser/NestedParenthesesParser.php b/src/Http/QueryParser/NestedParenthesesParser.php index b86554ee..d67ec9c8 100644 --- a/src/Http/QueryParser/NestedParenthesesParser.php +++ b/src/Http/QueryParser/NestedParenthesesParser.php @@ -9,15 +9,16 @@ class NestedParenthesesParser // current level protected array $currentScope = []; // input string to parse - protected ?string $query = null; + protected string $query = ''; // query split protected ?array $querySplit = null; // current character offset in string - protected ?int $currentPosition = null; + protected int $currentPosition = 0; protected ?string $lastJoiner = null; // start of text-buffer protected ?int $bufferStartAt = null; + protected int $length = 0; // Ignore current char meaning on the iteration protected bool $ignoreMode = false; diff --git a/src/Http/QueryParser/NotQueryableFieldException.php b/src/Http/QueryParser/NotQueryableFieldException.php index 0c3f2439..a5bac1e6 100644 --- a/src/Http/QueryParser/NotQueryableFieldException.php +++ b/src/Http/QueryParser/NotQueryableFieldException.php @@ -2,7 +2,9 @@ namespace Baka\Http\QueryParser; -class NotQueryableFieldException extends \Exception +use Exception; + +class NotQueryableFieldException extends Exception { /** * @var string @@ -14,9 +16,9 @@ class NotQueryableFieldException extends \Exception * * @param string $field * @param int $code - * @param \Exception $previous + * @param Exception $previous */ - public function __construct(string $field, $code = 0, \Exception $previous = null) + public function __construct(string $field, $code = 0, Exception $previous = null) { $this->field = $field; parent::__construct('Field is not queryable: ' . $this->getField(), $code, $previous); diff --git a/src/Http/QueryParser/NotValuesProvidedException.php b/src/Http/QueryParser/NotValuesProvidedException.php index b268c50c..4d8e03aa 100644 --- a/src/Http/QueryParser/NotValuesProvidedException.php +++ b/src/Http/QueryParser/NotValuesProvidedException.php @@ -2,16 +2,18 @@ namespace Baka\Http\QueryParser; -class NotValuesProvidedException extends \Exception +use Exception; + +class NotValuesProvidedException extends Exception { /** * Constructor. * * @param string $field * @param int $code - * @param \Exception $previous + * @param Exception $previous */ - public function __construct(string $message = 'Not values provided to compare.', $code = 0, \Exception $previous = null) + public function __construct(string $message = 'Not values provided to compare.', $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Http/QueryParser/OutOfScopeOperatorException.php b/src/Http/QueryParser/OutOfScopeOperatorException.php index 9753f31c..fbd8a455 100644 --- a/src/Http/QueryParser/OutOfScopeOperatorException.php +++ b/src/Http/QueryParser/OutOfScopeOperatorException.php @@ -2,7 +2,9 @@ namespace Baka\Http\QueryParser; -class OutOfScopeOperatorException extends \Exception +use Exception; + +class OutOfScopeOperatorException extends Exception { /** * @var string @@ -14,9 +16,9 @@ class OutOfScopeOperatorException extends \Exception * * @param string $operator * @param int $code - * @param \Exception $previous + * @param Exception $previous */ - public function __construct(string $operator, $code = 0, \Exception $previous = null) + public function __construct(string $operator, $code = 0, Exception $previous = null) { $this->operator = $operator; parent::__construct('Operator can not be used with in the provided scope (comparison): ' . $this->getOperator(), $code, $previous); diff --git a/src/Http/QueryParser/QueryParser.php b/src/Http/QueryParser/QueryParser.php index 72c2cc92..9721a948 100644 --- a/src/Http/QueryParser/QueryParser.php +++ b/src/Http/QueryParser/QueryParser.php @@ -19,7 +19,8 @@ class QueryParser '>' => '>', '<' => '<', '!' => '!', - '¬' => 'BETWEEN', + '¬' => '>', + //'¬' => 'BETWEEN', ]; /** @@ -30,7 +31,8 @@ class QueryParser '>' => '>=', '<' => '<=', '!' => '<>', - 'BETWEEN' => 'BETWEEN', + 'BETWEEN' => '>', + //'BETWEEN' => 'BETWEEN', ]; /** @@ -346,6 +348,14 @@ protected function transformNestedComparisons(array &$comparisons) : string * * @param array $comparison The array of comparison elements * + * [field] => rating + * [operator] => ¬ + * [values] => 1|3 + * + * [field] => field.categories_id + * [operator] => : + * [values] => 2 + * * @return string */ protected function parseComparison(array $comparison) : string @@ -358,8 +368,16 @@ protected function parseComparison(array $comparison) : string $comparison = self::buildComparison($field, $operator, array_shift($values)); + /** + * Multi value operation + * - for OR or Between. + */ foreach ($values as $value) { - $comparison .= $operator == 'BETWEEN' ? ' AND ' . $value : ' OR ' . self::buildComparison($field, $operator, $value); + /** + * @todo temp solution to handle between while this pull is merged https://github.com/opendistro-for-elasticsearch/sql/pull/1067 + */ + $comparison .= $operator == '>' ? ' AND ' . $field . ' <= ' . $value : ' OR ' . self::buildComparison($field, $operator, $value); + //$comparison .= $operator == 'BETWEEN' ? ' AND ' . $value : ' OR ' . self::buildComparison($field, $operator, $value); } return $comparison; diff --git a/src/Http/QueryParser/UnknownOperatorException.php b/src/Http/QueryParser/UnknownOperatorException.php index 55e95469..92bf33d4 100644 --- a/src/Http/QueryParser/UnknownOperatorException.php +++ b/src/Http/QueryParser/UnknownOperatorException.php @@ -2,7 +2,9 @@ namespace Baka\Http\QueryParser; -class UnknownOperatorException extends \Exception +use Exception; + +class UnknownOperatorException extends Exception { /** * @var string @@ -14,9 +16,9 @@ class UnknownOperatorException extends \Exception * * @param string $operator * @param int $code - * @param \Exception $previous + * @param Exception $previous */ - public function __construct(string $operator, $code = 0, \Exception $previous = null) + public function __construct(string $operator, $code = 0, Exception $previous = null) { $this->operator = $operator; parent::__construct('Unknown operator: ' . $this->getOperator(), $code, $previous);