-
Notifications
You must be signed in to change notification settings - Fork 10
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
WIP: Add ranges support #14
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #14 +/- ##
=======================================
Coverage 100% 100%
- Complexity 260 279 +19
=======================================
Files 47 49 +2
Lines 689 743 +54
=======================================
+ Hits 689 743 +54
Continue to review full report at Codecov.
|
|
||
/** | ||
* @param string $lexeme | ||
* @param int $position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No alignment in PHPDoc, it unnecessarily adds to diff when updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just run the php-cs-fixer with the current settings, I guess it was never run before on the code.
I guess it is a good thing to comply to a CS here :)
@@ -46,43 +48,63 @@ protected function getExpressionTypeMap() | |||
protected function createTermToken($position, array $data) | |||
{ | |||
$lexeme = $data['lexeme']; | |||
$token = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I think Code Climate is a bit too aggressive, this now looks harder to read than before :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the code climate settings? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I reverted that change! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now disabled argument count as well. Unfortunately it has no separate config for constructors.
This looks great :) Do you plan to go for the exclusive ranges here as well? |
feb20c4
to
6af5e8b
Compare
@pspanja the exclusive should be "easy" to achive, but there is something not clear to me in the regexp you're using in the phrase token: And for now, the "208-04-05" format in the range is not supported yet |
@pspanja inclusive/exclusive range added, I'll add later the support for the date ranges |
25e49ce
to
285543d
Compare
It's negative lookbehind, see here: http://www.rexegg.com/regex-lookarounds.html About left and right value in range matching - I think we should somehow reuse the pattern for matching a word. Will take a closer look in the evening. |
Thanks for the explanation @pspanja! |
6ce8597
to
a7c3867
Compare
*/ | ||
public static function getTypeByStart($startSymbol) | ||
{ | ||
if ('[' === $startSymbol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this check here means if someone customizes the symbol, this class will also need to be changed. So it should be rather done outside, in the Full
TokenExtractor
implementation.
|
||
switch ($token->type) { | ||
case RangeToken::TYPE_INCLUSIVE: | ||
return $domainPrefix . '[' . $token->rangeFrom . ' TO ' . $token->rangeTo . ']'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbols should be captured by the expression and contained in the token, so if they are customized this class does not need to know about it. And we should support mixed case as well, {a TO b]
and [a TO b}
.
It will probably mean a truckload of constructor arguments, but I'm OK with that :)
It can be split, I'm OK with that. Thinking about the implementation a bit, handling both two-sided and one-sided ranges seems like too much both for the regex and token, so should probably be handled with a separate pattern and a separate token. |
528b2b4
to
0aee897
Compare
0aee897
to
771b486
Compare
Hi guys, thank you for this cool PR! |
Hi @TomasPilar, I'll try to find time in the next few days to see how to push this further. |
FYI: this MR has been used in a pre-production system from April 6 :) |
This looks like a very useful extension — any chance it will be merged/released in the near future? |
Hi @j13k, I've neglected this because I was too busy, but I'll find time in the next weeks to take care of it. It's obviously needed :) |
That's fine @pspanja, I know what it's like! I'm struggling to find time for an outstanding PR on a small project that I maintain. ;) Just so you know, it's a very useful library and really well-executed. I've implemented a set of generator classes that convert queries to Elasticsearch DSL. |
I agree with @j13k , this library was very useful for me to:
|
Any plan to merge this PR? Thank you. |
[a TO b]
ranges{a TO b}
ranges[a TO b}
)xxxx-xx-xx
format*
in ranges, example:[123 TO *]
["2008-07-28T14:47:31Z" TO NOW]