-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Add back range support to ip
fields.
#17777
Conversation
InetAddresses.forString("2001:db8::1"), | ||
InetAddresses.forString("2001:db8::fffe")), | ||
ft.rangeQuery("2001:db8::", "2001:db8::ffff", false, false)); | ||
} |
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.
What about passing in the same value for upper and lower, and both inclusive=false. This should be an invalid range right? Do we have a check for that?
LGTM |
this looks correct to me (for ipv4 and ipv6). we encode into internal format (which is always 128 bits) and treat it as a 128-bit number, adding or subtracting one to the endpoints. maybe it would be good to test out some of the real corner cases (address already all zeros or all 1s, addresses on the ipv4-mapped boundary). Its not clear to me what will happen, i think probably a strange exception from numericutils. |
Thanks for the endpoints test. I'm not sure if its worth trying to improve the exception to be more understandable by the user (maybe the generic one could be improved, but it would still be limited to generic terms like underflow/overflow). As far as the "boundaries" I meant more the cases around |
Also, I strongly dislike booleans and nulls in the lucene api, but if we are going to support this thing, maybe we should consider methods in InetAddressPoint.java like:
These could have better error messages for overflow and anyone wanting to do this can do it in a less fragile way. |
Also, it is worth thinking about consistency for these ranges across all types as much as possible. Do integer/long fields throw exceptions in these cases or will Integer.MAX_VALUE exclusive still return Integer.MAX_VALUE? For double/float fields the behavior may really need to be different, depends if you think -Infinity exclusive will still include -Infinity and so on. |
They return a MatchNoDocsQuery in that case since there is no greator integer than MAX_VALUE. We could do the same for ip addresses.
Right, this is what is happening right now. If you pass POSITIVE_INFINITY as a lower bound and it is exclusive, then we just call Math.nextUp which returns POSITIVE_INFINITY. So POSITIVE_INFINITY will be included in practice. |
|
Technically i think NaN is better here (it sorts after POSITIVE_INFINITY). In all cases I don't know what to suggest: this is why i really think having an api taking booleans and nulls is unintuitive and too hard to reason about. All of these problems are artificially created by a bad query DSL. |
69cf104
to
29a2c7f
Compare
I pushed one more commit. I had to fork some Lucene code in order to be able to leverage the new nextUp/nextDown functions and have the fix for The range method now behaves consistently with integers: if the lower (resp. upper) bound is the maximum (resp. minimum) value and is not inclusive, then a MatchNoDocsQuery is returned. |
`ip` fields currently fail range queries when either bound is inclusive. This commit makes ranges also work in the exclusive case to be consistent with other data types.
29a2c7f
to
370af45
Compare
ip
fields currently fail range queries when either bound is inclusive. Thiscommit makes ranges also work in the exclusive case to be consistent with other
data types.
Relates to #17971