Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.7] Intermedium Between #115

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Elasticsearch/Objects/Documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Http/QueryParser/NestedParenthesesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/Http/QueryParser/NotQueryableFieldException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Baka\Http\QueryParser;

class NotQueryableFieldException extends \Exception
use Exception;

class NotQueryableFieldException extends Exception
{
/**
* @var string
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/Http/QueryParser/NotValuesProvidedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Http/QueryParser/OutOfScopeOperatorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Baka\Http\QueryParser;

class OutOfScopeOperatorException extends \Exception
use Exception;

class OutOfScopeOperatorException extends Exception
{
/**
* @var string
Expand All @@ -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);
Expand Down
24 changes: 21 additions & 3 deletions src/Http/QueryParser/QueryParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class QueryParser
'>' => '>',
'<' => '<',
'!' => '!',
'¬' => 'BETWEEN',
'¬' => '>',
//'¬' => 'BETWEEN',
];

/**
Expand All @@ -30,7 +31,8 @@ class QueryParser
'>' => '>=',
'<' => '<=',
'!' => '<>',
'BETWEEN' => 'BETWEEN',
'BETWEEN' => '>',
//'BETWEEN' => 'BETWEEN',
];

/**
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/Http/QueryParser/UnknownOperatorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Baka\Http\QueryParser;

class UnknownOperatorException extends \Exception
use Exception;

class UnknownOperatorException extends Exception
{
/**
* @var string
Expand All @@ -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);
Expand Down