-
Notifications
You must be signed in to change notification settings - Fork 32
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
fix: wildcards in numeric range queries #75
Conversation
When the `*` symbol is used in ranges, the parsing dies with a `NullPointerException`. That is because input strings with the `null` value are not handled -- they should be treated as infinity with the respective sign (depending on the side of range where the wildcard is used).
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.
Unit tests pass. Also tested with make mango-test
and make elixir-suite
.
if (isNumber(lower) && isNumber(upper)) { | ||
NumericRangeQuery.newDoubleRange(field, 8, lower.toDouble, | ||
upper.toDouble, startInclusive, endInclusive) | ||
val lb = Option(lower).getOrElse("-Infinity") |
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.
this appears to expand the syntax to mean any input that the parser yielded null for will be a valid open range, which boxes us in for future changes and I think is unintentional?
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 would prefer to see the NPE handled. If it occurs in;
private def isNumber(str: String): Boolean = {
fpRegex.matcher(str).matches()
}
then we should just change isNumber to return false if str is 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.
The null
values in the second and third parameters of QueryParser/getRangeQuery()
have a special meaning. It denotes the start and end of open ranges as suggested by the sources of Lucene 4.6.1:
boolean startOpen=false;
boolean endOpen=false;
if (goop1.kind == RANGE_QUOTED) {
goop1.image = goop1.image.substring(1, goop1.image.length()-1);
} else if ("*".equals(goop1.image)) {
startOpen=true;
}
if (goop2.kind == RANGE_QUOTED) {
goop2.image = goop2.image.substring(1, goop2.image.length()-1);
} else if ("*".equals(goop2.image)) {
endOpen=true;
}
q = getRangeQuery(field, startOpen ? null : discardEscapeChar(goop1.image), endOpen ? null : discardEscapeChar(goop2.image), startInc, endInc);
You can also see in the toString()
method of TermRangeQuery
that null
s are uniquely translated back to stars:
buffer.append(includeLower ? '[' : '{');
buffer.append(lowerTerm != null ? ("*".equals(Term.toString(lowerTerm)) ? "\\*" : Term.toString(lowerTerm)) : "*");
buffer.append(" TO ");
buffer.append(upperTerm != null ? ("*".equals(Term.toString(upperTerm)) ? "\\*" : Term.toString(upperTerm)) : "*");
buffer.append(includeUpper ? ']' : '}');
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.
aha, great, thanks for digging in.
When the
*
(wildcard) symbol is used in ranges, the parsing dies with aNullPointerException
. That is because input strings with thenull
value are not handled -- they should be treated as infinity with the respective sign (depending on the side of range where the wildcard is used).