lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r881986 - in /lucene/solr/trunk/src/java/org/apache/solr/search/function/distance: DistanceUtils.java GeohashHaversineFunction.java HaversineFunction.java
Date Wed, 18 Nov 2009 23:02:38 GMT
Author: gsingers
Date: Wed Nov 18 23:02:38 2009
New Revision: 881986

URL: http://svn.apache.org/viewvc?rev=881986&view=rev
Log:
SOLR-1302: clean up some docs, handle null geohash such that if one of the entries is null,
treat it as infinite distance

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
    lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
    lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java?rev=881986&r1=881985&r2=881986&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
Wed Nov 18 23:02:38 2009
@@ -34,6 +34,7 @@
    */
   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;

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java?rev=881986&r1=881985&r2=881986&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
Wed Nov 18 23:02:38 2009
@@ -93,11 +93,13 @@
     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;
   }

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java?rev=881986&r1=881985&r2=881986&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
Wed Nov 18 23:02:38 2009
@@ -66,16 +66,12 @@
    * @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);
   }
 
 



Mime
View raw message