lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r995267 - in /lucene/dev/trunk/solr: CHANGES.txt src/java/org/apache/solr/search/ValueSourceParser.java src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
Date Wed, 08 Sep 2010 22:29:33 GMT
Author: gsingers
Date: Wed Sep  8 22:29:32 2010
New Revision: 995267

URL: http://svn.apache.org/viewvc?rev=995267&view=rev
Log:
SOLR-2114: fix parsing error in hsin function

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=995267&r1=995266&r2=995267&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Wed Sep  8 22:29:32 2010
@@ -466,6 +466,8 @@ Bug Fixes
   prevent an exception in one facet command from affecting another
   facet command. (yonik)
 
+* SOLR-2114: Fixed parsing error in hsin function.  The function signature has changed slightly.
(gsingers)  
+
 
 Other Changes
 ----------------------

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java?rev=995267&r1=995266&r2=995267&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java Wed Sep 
8 22:29:32 2010
@@ -241,12 +241,17 @@ public abstract class ValueSourceParser 
       public ValueSource parse(FunctionQParser fp) throws ParseException {
 
         double radius = fp.parseDouble();
+        //SOLR-2114, make the convert flag required, since the parser doesn't support much
in the way of lookahead or the ability to convert a String into a ValueSource
+        boolean convert = Boolean.parseBoolean(fp.parseArg());
+        
         MultiValueSource pv1;
         MultiValueSource pv2;
 
         ValueSource one = fp.parseValueSource();
         ValueSource two = fp.parseValueSource();
         if (fp.hasMoreArguments()) {
+
+
           List<ValueSource> s1 = new ArrayList<ValueSource>();
           s1.add(one);
           s1.add(two);
@@ -267,10 +272,7 @@ public abstract class ValueSourceParser 
                     "Input must either be 2 MultiValueSources, or there must be 4 ValueSources");
           }
         }
-        boolean convert = false;
-        if (fp.hasMoreArguments()){
-          convert = Boolean.parseBoolean(fp.parseArg());
-        }
+
         return new HaversineFunction(pv1, pv2, radius, convert);
       }
     });

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java?rev=995267&r1=995266&r2=995267&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
(original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
Wed Sep  8 22:29:32 2010
@@ -44,16 +44,18 @@ public class DistanceFunctionTest extend
     assertU(adoc("id", "4", "x_td", String.valueOf(Math.PI / 4), "y_td", String.valueOf(Math.PI
/ 4), "gh_s", GeoHashUtils.encode(32.7693246, -81.9289094)));
     assertU(adoc("id", "5", "x_td", "45.0", "y_td", "45.0",
             "gh_s", GeoHashUtils.encode(32.7693246, -81.9289094)));
-    assertU(adoc("id", "6", "point_hash", "32.5, -79.0"));
-    assertU(adoc("id", "7", "point_hash", "32.6, -78.0"));
+    assertU(adoc("id", "6", "point_hash", "32.5, -79.0", "point", "32.5, -79.0"));
+    assertU(adoc("id", "7", "point_hash", "32.6, -78.0", "point", "32.6, -78.0"));
     assertU(commit());
     //Get the haversine distance between the point 0,0 and the docs above assuming a radius
of 1
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:1"),
"//float[@name='score']='0.0'");
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:2"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:3"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0)", "fq", "id:4"),
"//float[@name='score']='1.0471976'");
-    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, x_td, y_td, 0, 0, true)", "fq", "id:5"),
"//float[@name='score']='1.0471976'");
-
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:1"),
"//float[@name='score']='0.0'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:2"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:3"),
"//float[@name='score']='" + (float) (Math.PI / 2) + "'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:4"),
"//float[@name='score']='1.0471976'");
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(1, true, x_td, y_td, 0, 0)", "fq", "id:5"),
"//float[@name='score']='1.0471976'");
+    //SOLR-2114
+    assertQ(req("fl", "*,score", "q", "{!func}hsin(6371.009, true, point, vector(0, 0))",
"fq", "id:6"), "//float[@name='score']='8977.814'");
+    
     //Geo Hash Haversine
     //Can verify here: http://www.movable-type.co.uk/scripts/latlong.html, but they use a
slightly different radius for the earth, so just be close
     assertQ(req("fl", "*,score", "q", "{!func}ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM
+ ", gh_s, \"" + GeoHashUtils.encode(32, -79) +
@@ -67,6 +69,7 @@ public class DistanceFunctionTest extend
 
 
     assertQ(req("fl", "*,score", "q", "{!func}ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM
+ ", gh_s, geohash(32, -79))", "fq", "id:1"), "//float[@name='score']='122.171875'");
+
   }
 
   @Test



Mime
View raw message