SOLR-1302: clean up some docs, handle null geohash such that if one of the entries is null, treat it as infinite distance

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@881986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2009-11-18 23:02:38 +00:00
parent 05b4be62ec
commit 52283c86f8
3 changed files with 5 additions and 6 deletions

View File

@ -34,6 +34,7 @@ public class DistanceUtils {
*/
public static double haversine(double x1, double y1, double x2, double y2, double radius){
double result = 0;
//make sure they aren't all the same, as then we can just return 0
if ((x1 != x2) || (y1 != y2)) {
double diffX = x1 - x2;
double diffY = y1 - y2;

View File

@ -93,11 +93,13 @@ public class GeohashHaversineFunction extends ValueSource {
double result = 0;
String h1 = gh1DV.strVal(doc);
String h2 = gh2DV.strVal(doc);
if (h1.equals(h2) == false){
if (h1 != null && h2 != null && h1.equals(h2) == false){
double[] h1Pair = GeoHashUtils.decode(h1);
double[] h2Pair = GeoHashUtils.decode(h2);
result = DistanceUtils.haversine(Math.toRadians(h1Pair[0]), Math.toRadians(h1Pair[1]),
Math.toRadians(h2Pair[0]), Math.toRadians(h2Pair[1]), radius);
} else if (h1 == null || h2 == null){
result = Double.MAX_VALUE;
}
return result;
}

View File

@ -66,16 +66,12 @@ public class HaversineFunction extends ValueSource {
* @return The haversine distance formula
*/
protected double distance(int doc, DocValues x1DV, DocValues y1DV, DocValues x2DV, DocValues y2DV) {
double result = 0;
double x1 = x1DV.doubleVal(doc); //in radians
double y1 = y1DV.doubleVal(doc);
double x2 = x2DV.doubleVal(doc);
double y2 = y2DV.doubleVal(doc);
//make sure they aren't all the same, as then we can just return 0
result = DistanceUtils.haversine(x1, y1, x2, y2, radius);
return result;
return DistanceUtils.haversine(x1, y1, x2, y2, radius);
}