Fix parsing of "geo_distance" filter wrt "distance" / "unit" parameters
The problem was that when "unit" was given, the conversion to miles was happening too early, which caused wrong computations. This change postpones this computation when one really knows which unit should be used.
This commit is contained in:
parent
9b206146e3
commit
c08ad0cad6
|
@ -74,7 +74,8 @@ public class GeoDistanceFilterParser extends AbstractIndexComponent implements X
|
||||||
double lon = 0;
|
double lon = 0;
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
double distance = 0;
|
double distance = 0;
|
||||||
DistanceUnit unit = null;
|
Object vDistance = null;
|
||||||
|
DistanceUnit unit = DistanceUnit.KILOMETERS; // default unit
|
||||||
GeoDistance geoDistance = GeoDistance.ARC;
|
GeoDistance geoDistance = GeoDistance.ARC;
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
|
@ -110,9 +111,9 @@ public class GeoDistanceFilterParser extends AbstractIndexComponent implements X
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if (currentFieldName.equals("distance")) {
|
if (currentFieldName.equals("distance")) {
|
||||||
if (token == XContentParser.Token.VALUE_STRING) {
|
if (token == XContentParser.Token.VALUE_STRING) {
|
||||||
distance = DistanceUnit.parse(parser.text(), DistanceUnit.KILOMETERS, DistanceUnit.MILES);
|
vDistance = parser.text(); // a String
|
||||||
} else {
|
} else {
|
||||||
distance = parser.doubleValue();
|
vDistance = parser.numberValue(); // a Number
|
||||||
}
|
}
|
||||||
} else if (currentFieldName.equals("unit")) {
|
} else if (currentFieldName.equals("unit")) {
|
||||||
unit = DistanceUnit.fromString(parser.text());
|
unit = DistanceUnit.fromString(parser.text());
|
||||||
|
@ -150,8 +151,10 @@ public class GeoDistanceFilterParser extends AbstractIndexComponent implements X
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit != null) {
|
if (vDistance instanceof Number) {
|
||||||
distance = unit.toMiles(distance);
|
distance = unit.toMiles(((Number)vDistance).doubleValue());
|
||||||
|
} else {
|
||||||
|
distance = DistanceUnit.parse((String)vDistance, unit, DistanceUnit.MILES);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapperService mapperService = parseContext.mapperService();
|
MapperService mapperService = parseContext.mapperService();
|
||||||
|
|
Loading…
Reference in New Issue