You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ry...@apache.org on 2012/03/14 00:28:19 UTC

svn commit: r1300409 - in /lucene/dev/trunk: ./ dev-tools/eclipse/ dev-tools/idea/.idea/ dev-tools/idea/lucene/contrib/ dev-tools/idea/lucene/contrib/spatial/ dev-tools/idea/modules/spatial/ dev-tools/maven/ dev-tools/maven/lucene/contrib/ dev-tools/ma...

Author: ryan
Date: Tue Mar 13 23:28:17 2012
New Revision: 1300409

URL: http://svn.apache.org/viewvc?rev=1300409&view=rev
Log:
LUCENE-3795: Replace contrib/spatial with modules/spatial  (merge from branch)

Added:
    lucene/dev/trunk/dev-tools/idea/modules/spatial/
      - copied from r1300396, lucene/dev/branches/lucene3795_lsp_spatial_module/dev-tools/idea/modules/spatial/
    lucene/dev/trunk/dev-tools/maven/modules/spatial/
      - copied from r1300396, lucene/dev/branches/lucene3795_lsp_spatial_module/dev-tools/maven/modules/spatial/
    lucene/dev/trunk/modules/spatial/   (props changed)
      - copied from r1300396, lucene/dev/branches/lucene3795_lsp_spatial_module/modules/spatial/
    lucene/dev/trunk/solr/lib/spatial4j-0.2.jar
      - copied unchanged from r1300396, lucene/dev/branches/lucene3795_lsp_spatial_module/solr/lib/spatial4j-0.2.jar
    lucene/dev/trunk/solr/lib/spatial4j-LICENSE-ASL.txt
      - copied unchanged from r1300396, lucene/dev/branches/lucene3795_lsp_spatial_module/solr/lib/spatial4j-LICENSE-ASL.txt
    lucene/dev/trunk/solr/lib/spatial4j-NOTICE.txt
      - copied unchanged from r1300396, lucene/dev/branches/lucene3795_lsp_spatial_module/solr/lib/spatial4j-NOTICE.txt
Removed:
    lucene/dev/trunk/dev-tools/idea/lucene/contrib/spatial/
    lucene/dev/trunk/dev-tools/maven/lucene/contrib/spatial/
    lucene/dev/trunk/lucene/contrib/spatial/
Modified:
    lucene/dev/trunk/   (props changed)
    lucene/dev/trunk/dev-tools/eclipse/dot.classpath
    lucene/dev/trunk/dev-tools/idea/.idea/ant.xml
    lucene/dev/trunk/dev-tools/idea/.idea/modules.xml
    lucene/dev/trunk/dev-tools/idea/.idea/workspace.xml
    lucene/dev/trunk/dev-tools/idea/lucene/contrib/   (props changed)
    lucene/dev/trunk/dev-tools/maven/lucene/contrib/pom.xml.template
    lucene/dev/trunk/dev-tools/maven/modules/pom.xml.template
    lucene/dev/trunk/dev-tools/maven/pom.xml.template
    lucene/dev/trunk/lucene/   (props changed)
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/build.xml
    lucene/dev/trunk/lucene/contrib/CHANGES.txt   (props changed)
    lucene/dev/trunk/lucene/contrib/contrib-build.xml
    lucene/dev/trunk/lucene/contrib/sandbox/src/test/org/apache/lucene/sandbox/queries/regex/TestSpanRegexQuery.java   (props changed)
    lucene/dev/trunk/modules/analysis/kuromoji/   (props changed)
    lucene/dev/trunk/modules/benchmark/   (props changed)
    lucene/dev/trunk/modules/facet/   (props changed)
    lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeFilterBuilder.java   (props changed)
    lucene/dev/trunk/modules/spatial/lib/   (props changed)
    lucene/dev/trunk/solr/   (props changed)
    lucene/dev/trunk/solr/CHANGES.txt   (props changed)
    lucene/dev/trunk/solr/README.txt   (props changed)
    lucene/dev/trunk/solr/build.xml   (props changed)
    lucene/dev/trunk/solr/common-build.xml   (props changed)
    lucene/dev/trunk/solr/contrib/   (props changed)
    lucene/dev/trunk/solr/contrib/dataimporthandler-extras/src/java/   (props changed)
    lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/   (props changed)
    lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/   (props changed)
    lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/   (props changed)
    lucene/dev/trunk/solr/contrib/uima/src/java/   (props changed)
    lucene/dev/trunk/solr/contrib/uima/src/test-files/   (props changed)
    lucene/dev/trunk/solr/core/   (props changed)
    lucene/dev/trunk/solr/core/src/java/   (props changed)
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/GeoHashField.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialOptions.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/SquaredEuclideanFunction.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java
    lucene/dev/trunk/solr/core/src/test/   (props changed)
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
    lucene/dev/trunk/solr/example/   (props changed)
    lucene/dev/trunk/solr/lib/   (props changed)
    lucene/dev/trunk/solr/solrj/   (props changed)
    lucene/dev/trunk/solr/solrj/src/java/   (props changed)
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/   (props changed)
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/   (props changed)
    lucene/dev/trunk/solr/test-framework/   (props changed)
    lucene/dev/trunk/solr/webapp/   (props changed)

Modified: lucene/dev/trunk/dev-tools/eclipse/dot.classpath
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/eclipse/dot.classpath?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/eclipse/dot.classpath (original)
+++ lucene/dev/trunk/dev-tools/eclipse/dot.classpath Tue Mar 13 23:28:17 2012
@@ -14,10 +14,8 @@
 	<classpathentry kind="src" path="lucene/contrib/misc/src/test"/>
 	<classpathentry kind="src" path="lucene/contrib/sandbox/src/java"/>
 	<classpathentry kind="src" path="lucene/contrib/sandbox/src/test"/>
-	<classpathentry kind="src" path="lucene/contrib/spatial/src/java"/>
-	<classpathentry kind="src" path="lucene/contrib/spatial/src/test"/>
 	<classpathentry kind="src" path="lucene/test-framework/src/java"/>
-        <classpathentry kind="src" output="bin.tests-framework" path="lucene/test-framework/src/resources"/>
+  <classpathentry kind="src" output="bin.tests-framework" path="lucene/test-framework/src/resources"/>
 	<classpathentry kind="src" path="modules/analysis/common/src/java"/>
 	<classpathentry kind="src" path="modules/analysis/common/src/resources"/>
 	<classpathentry kind="src" path="modules/analysis/common/src/test"/>
@@ -55,6 +53,10 @@
 	<classpathentry kind="src" path="modules/queryparser/src/test"/>
 	<classpathentry kind="src" path="modules/suggest/src/java"/>
 	<classpathentry kind="src" path="modules/suggest/src/test"/>
+	<classpathentry kind="src" path="modules/spatial/src/java"/>
+	<classpathentry kind="src" path="modules/spatial/src/test"/>
+	<classpathentry kind="src" path="modules/spatial/src/test-files"/>
+	<classpathentry kind="lib" path="modules/spatial/lib/spatial4j-0.2.jar"/>
 	<classpathentry kind="src" path="solr/core/src/java"/>
 	<classpathentry kind="src" path="solr/core/src/test"/>
 	<classpathentry kind="src" path="solr/core/src/test-files"/>

Modified: lucene/dev/trunk/dev-tools/idea/.idea/ant.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/idea/.idea/ant.xml?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/idea/.idea/ant.xml (original)
+++ lucene/dev/trunk/dev-tools/idea/.idea/ant.xml Tue Mar 13 23:28:17 2012
@@ -8,7 +8,6 @@
     <buildFile url="file://$PROJECT_DIR$/lucene/contrib/memory/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/lucene/contrib/misc/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/lucene/contrib/sandbox/build.xml" />
-    <buildFile url="file://$PROJECT_DIR$/lucene/contrib/spatial/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/lucene/core/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/lucene/tools/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/lucene/test-framework/build.xml" />
@@ -26,6 +25,7 @@
     <buildFile url="file://$PROJECT_DIR$/modules/join/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/modules/queries/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/modules/queryparser/build.xml" />
+    <buildFile url="file://$PROJECT_DIR$/modules/spatial/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/modules/suggest/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/solr/build.xml" />
     <buildFile url="file://$PROJECT_DIR$/solr/core/build.xml" />

Modified: lucene/dev/trunk/dev-tools/idea/.idea/modules.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/idea/.idea/modules.xml?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/idea/.idea/modules.xml (original)
+++ lucene/dev/trunk/dev-tools/idea/.idea/modules.xml Tue Mar 13 23:28:17 2012
@@ -9,7 +9,6 @@
       <module filepath="$PROJECT_DIR$/lucene/contrib/memory/memory.iml" />
       <module filepath="$PROJECT_DIR$/lucene/contrib/misc/misc.iml" />
       <module filepath="$PROJECT_DIR$/lucene/contrib/sandbox/sandbox.iml" />
-      <module filepath="$PROJECT_DIR$/lucene/contrib/spatial/spatial.iml" />
       <module filepath="$PROJECT_DIR$/modules/analysis/common/analysis-common.iml" />
       <module filepath="$PROJECT_DIR$/modules/analysis/icu/icu.iml" />
       <module filepath="$PROJECT_DIR$/modules/analysis/kuromoji/kuromoji.iml" />
@@ -24,6 +23,7 @@
       <module filepath="$PROJECT_DIR$/modules/join/join.iml" />
       <module filepath="$PROJECT_DIR$/modules/queries/queries.iml" />
       <module filepath="$PROJECT_DIR$/modules/queryparser/queryparser.iml" />
+      <module filepath="$PROJECT_DIR$/modules/spatial/spatial.iml" />
       <module filepath="$PROJECT_DIR$/modules/suggest/suggest.iml" />
       <module filepath="$PROJECT_DIR$/solr/solr.iml" />
       <module filepath="$PROJECT_DIR$/solr/contrib/analysis-extras/analysis-extras.iml" />

Modified: lucene/dev/trunk/dev-tools/idea/.idea/workspace.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/idea/.idea/workspace.xml?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/idea/.idea/workspace.xml (original)
+++ lucene/dev/trunk/dev-tools/idea/.idea/workspace.xml Tue Mar 13 23:28:17 2012
@@ -172,10 +172,10 @@
       <option name="VM_PARAMETERS" value="-ea -Dtests.luceneMatchVersion=4.0 -DtempDir=temp -Djetty.testMode=1 -Djetty.insecurerandom=1 -Dsolr.directoryFactory=org.apache.solr.core.MockDirectoryFactory" />
       <option name="TEST_SEARCH_SCOPE"><value defaultName="singleModule" /></option>
     </configuration>
-    <configuration default="false" name="spatial contrib" type="JUnit" factoryName="JUnit">
+    <configuration default="false" name="spatial module" type="JUnit" factoryName="JUnit">
       <module name="spatial" />
       <option name="TEST_OBJECT" value="package" />
-      <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/lucene/build/contrib/spatial" />
+      <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/modules/spatial/build" />
       <option name="VM_PARAMETERS" value="-ea -DtempDir=temp" />
       <option name="TEST_SEARCH_SCOPE"><value defaultName="singleModule" /></option>
     </configuration>

Modified: lucene/dev/trunk/dev-tools/maven/lucene/contrib/pom.xml.template
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/maven/lucene/contrib/pom.xml.template?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/maven/lucene/contrib/pom.xml.template (original)
+++ lucene/dev/trunk/dev-tools/maven/lucene/contrib/pom.xml.template Tue Mar 13 23:28:17 2012
@@ -36,7 +36,6 @@
     <module>memory</module>
     <module>misc</module>
     <module>sandbox</module>
-    <module>spatial</module>
   </modules>
   <build>
     <directory>build/lucene-contrib-aggregator</directory>

Modified: lucene/dev/trunk/dev-tools/maven/modules/pom.xml.template
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/maven/modules/pom.xml.template?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/maven/modules/pom.xml.template (original)
+++ lucene/dev/trunk/dev-tools/maven/modules/pom.xml.template Tue Mar 13 23:28:17 2012
@@ -38,6 +38,7 @@
     <module>join</module>
     <module>queries</module>
     <module>queryparser</module>
+    <module>spatial</module>
     <module>suggest</module>
   </modules>
   <build>

Modified: lucene/dev/trunk/dev-tools/maven/pom.xml.template
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/maven/pom.xml.template?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/maven/pom.xml.template (original)
+++ lucene/dev/trunk/dev-tools/maven/pom.xml.template Tue Mar 13 23:28:17 2012
@@ -344,6 +344,11 @@
         <artifactId>javax.servlet</artifactId>
         <version>3.0.0.v201112011016</version>
       </dependency>
+      <dependency>
+        <groupId>com.spatial4j</groupId>
+        <artifactId>spatial4j</artifactId>
+        <version>0.2</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
   <dependencies>

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Tue Mar 13 23:28:17 2012
@@ -682,6 +682,10 @@ Optimizations
   should be rounded up for better performance. This option only applies for docvalues types bytes fixed sorted
   and bytes var sorted. (Simon Willnauer, Martijn van Groningen)
   
+* LUCENE-3795: Replace contrib/spatial with modules/spatial.  This includes 
+  a basic spatial strategy interface.  (David Smiley, Chris Male, ryan)
+    
+  
 Bug fixes
 
 * LUCENE-2803: The FieldCache can miss values if an entry for a reader

Modified: lucene/dev/trunk/lucene/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/build.xml?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/build.xml (original)
+++ lucene/dev/trunk/lucene/build.xml Tue Mar 13 23:28:17 2012
@@ -264,7 +264,6 @@
           <packageset dir="contrib/memory/src/java"/>
           <packageset dir="contrib/misc/src/java"/>
           <packageset dir="contrib/sandbox/src/java"/>
-          <packageset dir="contrib/spatial/src/java"/>
           <!-- end alpha sort -->
 
           <!-- If the main javadoc Group listing includes an "Other   -->
@@ -279,7 +278,6 @@
           <group title="contrib: Memory" packages="org.apache.lucene.index.memory*"/>
           <group title="contrib: Misc " packages="org.apache.lucene.misc*"/>
           <group title="contrib: Sandbox" packages="org.apache.lucene.sandbox*"/>
-          <group title="contrib: Spatial" packages="org.apache.lucene.spatial*"/>
           
         </sources>
       </invoke-javadoc>

Modified: lucene/dev/trunk/lucene/contrib/contrib-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/contrib-build.xml?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/contrib-build.xml (original)
+++ lucene/dev/trunk/lucene/contrib/contrib-build.xml Tue Mar 13 23:28:17 2012
@@ -228,12 +228,12 @@
     <property name="sandbox.uptodate" value="true"/>
   </target>
 
-  <property name="spatial.jar" value="${common.dir}/build/contrib/spatial/lucene-spatial-${version}.jar"/>
+  <property name="spatial.jar" value="${common.dir}/../modules/spatial/build/lucene-spatial-${version}.jar"/>
   <target name="check-spatial-uptodate" unless="spatial.uptodate">
-    <contrib-uptodate name="spatial" jarfile="${spatial.jar}" property="spatial.uptodate"/>
+    <module-uptodate name="spatial" jarfile="${spatial.jar}" property="spatial.uptodate"/>
   </target>
   <target name="jar-spatial" unless="spatial.uptodate" depends="check-spatial-uptodate">
-  	<ant dir="${common.dir}/contrib/spatial" target="jar-core" inheritAll="false">
+  	<ant dir="${common.dir}/../modules/spatial" target="jar-core" inheritAll="false">
       <propertyset refid="uptodate.and.compiled.properties"/>
     </ant>
     <property name="spatial.uptodate" value="true"/>

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/GeoHashField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/GeoHashField.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/GeoHashField.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/GeoHashField.java Tue Mar 13 23:28:17 2012
@@ -22,9 +22,12 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.SortField;
-import org.apache.lucene.spatial.geohash.GeoHashUtils;
-import org.apache.lucene.spatial.DistanceUtils;
-import org.apache.lucene.spatial.tier.InvalidGeoException;
+import com.spatial4j.core.context.ParseUtils;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.context.simple.SimpleSpatialContext;
+import com.spatial4j.core.exception.InvalidShapeException;
+import com.spatial4j.core.util.GeohashUtils;
+import com.spatial4j.core.shape.Point;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.response.TextResponseWriter;
 import org.apache.solr.search.QParser;
@@ -41,11 +44,13 @@ import java.io.IOException;
  * href="http://en.wikipedia.org/wiki/Geohash">Geohash</a> field. The field is
  * provided as a lat/lon pair and is internally represented as a string.
  *
- * @see org.apache.lucene.spatial.DistanceUtils#parseLatitudeLongitude(double[], String)
+ * @see com.spatial4j.core.context.ParseUtils#parseLatitudeLongitude(double[], String) 
  */
 public class GeoHashField extends FieldType implements SpatialQueryable {
 
 
+  private final SpatialContext ctx = SimpleSpatialContext.GEO_KM;
+
   @Override
   public SortField getSortField(SchemaField field, boolean top) {
     return getStringSort(field, top);
@@ -57,11 +62,11 @@ public class GeoHashField extends FieldT
   public Query createSpatialQuery(QParser parser, SpatialOptions options) {
     double [] point = new double[0];
     try {
-      point = DistanceUtils.parsePointDouble(null, options.pointStr, 2);
-    } catch (InvalidGeoException e) {
+      point = ParseUtils.parsePointDouble(null, options.pointStr, 2);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
-    String geohash = GeoHashUtils.encode(point[0], point[1]);
+    String geohash = GeohashUtils.encodeLatLon(point[0], point[1]);
     //TODO: optimize this
     return new SolrConstantScoreQuery(new ValueSourceRangeFilter(new GeohashHaversineFunction(getValueSource(options.field, parser),
             new LiteralValueSource(geohash), options.radius), "0", String.valueOf(options.distance), true, true));
@@ -76,8 +81,8 @@ public class GeoHashField extends FieldT
 
   @Override
   public String toExternal(IndexableField f) {
-    double[] latLon = GeoHashUtils.decode(f.stringValue());
-    return latLon[0] + "," + latLon[1];
+    Point p = GeohashUtils.decode(f.stringValue(),ctx);
+    return p.getY() + "," + p.getX();
   }
 
 
@@ -87,11 +92,11 @@ public class GeoHashField extends FieldT
     // latitude, longitude
     double[] latLon = new double[0];
     try {
-      latLon = DistanceUtils.parseLatitudeLongitude(null, val);
-    } catch (InvalidGeoException e) {
+      latLon = ParseUtils.parseLatitudeLongitude(null, val);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
-    return GeoHashUtils.encode(latLon[0], latLon[1]);
+    return GeohashUtils.encodeLatLon(latLon[0], latLon[1]);
   }
 
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java Tue Mar 13 23:28:17 2012
@@ -22,14 +22,18 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.queries.function.ValueSourceScorer;
 import org.apache.lucene.queries.function.valuesource.VectorValueSource;
 import org.apache.lucene.search.*;
-import org.apache.lucene.spatial.DistanceUtils;
-import org.apache.lucene.spatial.tier.InvalidGeoException;
+import com.spatial4j.core.context.ParseUtils;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.context.simple.SimpleSpatialContext;
+import com.spatial4j.core.distance.DistanceCalculator;
+import com.spatial4j.core.distance.DistanceUtils;
+import com.spatial4j.core.distance.GeodesicSphereDistCalc;
+import com.spatial4j.core.exception.InvalidShapeException;
+import com.spatial4j.core.shape.Rectangle;
 import org.apache.lucene.util.Bits;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.response.TextResponseWriter;
 import org.apache.solr.search.*;
 
@@ -63,8 +67,8 @@ public class LatLonType extends Abstract
       int i = 0;
       double[] latLon;
       try {
-        latLon = DistanceUtils.parseLatitudeLongitude(null, externalVal);
-      } catch (InvalidGeoException e) {
+        latLon = ParseUtils.parseLatitudeLongitude(null, externalVal);
+      } catch (InvalidShapeException e) {
         throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
       }
       //latitude
@@ -91,9 +95,9 @@ public class LatLonType extends Abstract
     String[] p1;
     String[] p2;
     try {
-      p1 = DistanceUtils.parsePoint(null, part1, dimension);
-      p2 = DistanceUtils.parsePoint(null, part2, dimension);
-    } catch (InvalidGeoException e) {
+      p1 = ParseUtils.parsePoint(null, part1, dimension);
+      p2 = ParseUtils.parsePoint(null, part2, dimension);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
     BooleanQuery result = new BooleanQuery(true);
@@ -112,8 +116,8 @@ public class LatLonType extends Abstract
     
     String[] p1 = new String[0];
     try {
-      p1 = DistanceUtils.parsePoint(null, externalVal, dimension);
-    } catch (InvalidGeoException e) {
+      p1 = ParseUtils.parsePoint(null, externalVal, dimension);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
     BooleanQuery bq = new BooleanQuery(true);
@@ -131,65 +135,32 @@ public class LatLonType extends Abstract
   public Query createSpatialQuery(QParser parser, SpatialOptions options) {
     double[] point = null;
     try {
-      point = DistanceUtils.parseLatitudeLongitude(options.pointStr);
-    } catch (InvalidGeoException e) {
+      point = ParseUtils.parseLatitudeLongitude(options.pointStr);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
 
     // lat & lon in degrees
     double latCenter = point[LAT];
     double lonCenter = point[LONG];
-
-    point[0] = point[0] * DistanceUtils.DEGREES_TO_RADIANS;
-    point[1] = point[1] * DistanceUtils.DEGREES_TO_RADIANS;
-    //Get the distance
-
-    double[] tmp = new double[2];
-    //these calculations aren't totally accurate, but it should be good enough
-    //TODO: Optimize to do in single calculations.  Would need to deal with poles, prime meridian, etc.
-    double [] north = DistanceUtils.pointOnBearing(point[LAT], point[LONG], options.distance, 0, tmp, options.radius);
-    //This returns the point as radians, but we need degrees b/c that is what the field is stored as
-    double ur_lat = north[LAT] * DistanceUtils.RADIANS_TO_DEGREES;//get it now, as we are going to reuse tmp
-    double [] east = DistanceUtils.pointOnBearing(point[LAT], point[LONG], options.distance, DistanceUtils.DEG_90_AS_RADS, tmp, options.radius);
-    double ur_lon = east[LONG] * DistanceUtils.RADIANS_TO_DEGREES;
-    double [] south = DistanceUtils.pointOnBearing(point[LAT], point[LONG], options.distance, DistanceUtils.DEG_180_AS_RADS, tmp, options.radius);
-    double ll_lat = south[LAT] * DistanceUtils.RADIANS_TO_DEGREES;
-    double [] west = DistanceUtils.pointOnBearing(point[LAT], point[LONG], options.distance, DistanceUtils.DEG_270_AS_RADS, tmp, options.radius);
-    double ll_lon = west[LONG] * DistanceUtils.RADIANS_TO_DEGREES;
     
-
-    //TODO: can we reuse our bearing calculations?
-    double angDist = DistanceUtils.angularDistance(options.distance,
-            options.radius);//in radians
-
-    double latMin = -90.0, latMax = 90.0, lonMin = -180.0, lonMax = 180.0;
-    double lon2Min = -180.0, lon2Max = 180.0;  // optional second longitude restriction
-
-    // for the poles, do something slightly different - a polar "cap".
-    // Also, note point[LAT] is in radians, but ur and ll are in degrees
-    if (point[LAT] + angDist > DistanceUtils.DEG_90_AS_RADS) { // we cross the north pole
-      //we don't need a longitude boundary at all
-      latMin = Math.min(ll_lat, ur_lat);
-    } else if (point[LAT] - angDist < -DistanceUtils.DEG_90_AS_RADS) { // we cross the south pole
-      latMax = Math.max(ll_lat, ur_lat);
+    DistanceCalculator distCalc = new GeodesicSphereDistCalc.Haversine(options.units.earthRadius());
+    SpatialContext ctx = new SimpleSpatialContext(options.units,distCalc,null);
+    Rectangle bbox = DistanceUtils.calcBoxByDistFromPtDEG(latCenter, lonCenter, options.distance, ctx);
+    double latMin = bbox.getMinY();
+    double latMax = bbox.getMaxY();
+    double lonMin, lonMax, lon2Min, lon2Max;
+    if (bbox.getCrossesDateLine()) {
+       lonMin = -180;
+       lonMax = bbox.getMaxX();
+       lon2Min = bbox.getMinX();
+       lon2Max = 180;
     } else {
-      // set the latitude restriction as normal
-      latMin = ll_lat;
-      latMax = ur_lat;
-
-      if (ll_lon > ur_lon) {
-         // we crossed the +-180 deg longitude... need to make
-        // range queries of (-180 TO ur) OR (ll TO 180)
-        lonMin = -180;
-        lonMax = ur_lon;
-        lon2Min = ll_lon;
-        lon2Max = 180;
-      } else {
-        lonMin = ll_lon;
-        lonMax = ur_lon;
-      }
+       lonMin = bbox.getMinX();
+       lonMax = bbox.getMaxX();
+       lon2Min = -180;
+       lon2Max = 180;
     }
-
     
     // Now that we've figured out the ranges, build them!
     SchemaField latField = subField(options.field, LAT);
@@ -427,8 +398,8 @@ class SpatialDistanceQuery extends Exten
       this.lon2 = SpatialDistanceQuery.this.lon2;
       this.calcDist = SpatialDistanceQuery.this.calcDist;
 
-      this.latCenterRad = SpatialDistanceQuery.this.latCenter * DistanceUtils.DEGREES_TO_RADIANS;
-      this.lonCenterRad = SpatialDistanceQuery.this.lonCenter * DistanceUtils.DEGREES_TO_RADIANS;
+      this.latCenterRad = Math.toRadians(SpatialDistanceQuery.this.latCenter);
+      this.lonCenterRad = Math.toRadians(SpatialDistanceQuery.this.lonCenter);
       this.latCenterRad_cos = this.calcDist ? Math.cos(latCenterRad) : 0;
       this.dist = SpatialDistanceQuery.this.dist;
       this.planetRadius = SpatialDistanceQuery.this.planetRadius;
@@ -457,8 +428,8 @@ class SpatialDistanceQuery extends Exten
     }
 
     double dist(double lat, double lon) {
-      double latRad = lat * DistanceUtils.DEGREES_TO_RADIANS;
-      double lonRad = lon * DistanceUtils.DEGREES_TO_RADIANS;
+      double latRad = Math.toRadians(lat);
+      double lonRad = Math.toRadians(lon);
       
       // haversine, specialized to avoid a cos() call on latCenterRad
       double diffX = latCenterRad - latRad;

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java Tue Mar 13 23:28:17 2012
@@ -25,8 +25,9 @@ import org.apache.lucene.search.BooleanC
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.SortField;
-import org.apache.lucene.spatial.DistanceUtils;
-import org.apache.lucene.spatial.tier.InvalidGeoException;
+import com.spatial4j.core.context.ParseUtils;
+import com.spatial4j.core.distance.DistanceUtils;
+import com.spatial4j.core.exception.InvalidShapeException;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.MapSolrParams;
 import org.apache.solr.common.params.SolrParams;
@@ -72,8 +73,8 @@ public class PointType extends Coordinat
     String externalVal = value.toString();
     String[] point = new String[0];
     try {
-      point = DistanceUtils.parsePoint(null, externalVal, dimension);
-    } catch (InvalidGeoException e) {
+      point = ParseUtils.parsePoint(null, externalVal, dimension);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
 
@@ -137,9 +138,9 @@ public class PointType extends Coordinat
     String[] p1;
     String[] p2;
     try {
-      p1 = DistanceUtils.parsePoint(null, part1, dimension);
-      p2 = DistanceUtils.parsePoint(null, part2, dimension);
-    } catch (InvalidGeoException e) {
+      p1 = ParseUtils.parsePoint(null, part1, dimension);
+      p2 = ParseUtils.parsePoint(null, part2, dimension);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
     BooleanQuery result = new BooleanQuery(true);
@@ -155,8 +156,8 @@ public class PointType extends Coordinat
   public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) {
     String[] p1 = new String[0];
     try {
-      p1 = DistanceUtils.parsePoint(null, externalVal, dimension);
-    } catch (InvalidGeoException e) {
+      p1 = ParseUtils.parsePoint(null, externalVal, dimension);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
     //TODO: should we assert that p1.length == dimension?
@@ -179,8 +180,8 @@ public class PointType extends Coordinat
     Query result = null;
     double [] point = new double[0];
     try {
-      point = DistanceUtils.parsePointDouble(null, options.pointStr, dimension);
-    } catch (InvalidGeoException e) {
+      point = ParseUtils.parsePointDouble(null, options.pointStr, dimension);
+    } catch (InvalidShapeException e) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
     }
     if (dimension == 1){

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialFilterQParser.java Tue Mar 13 23:28:17 2012
@@ -19,8 +19,8 @@ package org.apache.solr.search;
 
 import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.spatial.geometry.DistanceUnits;
-import org.apache.lucene.spatial.DistanceUtils;
+import com.spatial4j.core.distance.DistanceUnits;
+import com.spatial4j.core.distance.DistanceUtils;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.params.SpatialParams;

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialOptions.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialOptions.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialOptions.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SpatialOptions.java Tue Mar 13 23:28:17 2012
@@ -16,9 +16,8 @@ package org.apache.solr.search;
  * limitations under the License.
  */
 
+import com.spatial4j.core.distance.DistanceUnits;
 import org.apache.solr.schema.SchemaField;
-import org.apache.lucene.spatial.geometry.DistanceUnits;
-
 
 /**
  *

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java Tue Mar 13 23:28:17 2012
@@ -34,7 +34,6 @@ import org.apache.lucene.search.spell.Ja
 import org.apache.lucene.search.spell.LevensteinDistance;
 import org.apache.lucene.search.spell.NGramDistance;
 import org.apache.lucene.search.spell.StringDistance;
-import org.apache.lucene.spatial.DistanceUtils;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.UnicodeUtil;
 import org.apache.solr.common.SolrException;
@@ -44,7 +43,6 @@ import org.apache.solr.schema.*;
 
 import org.apache.solr.search.function.distance.*;
 import org.apache.solr.util.plugin.NamedListInitializedPlugin;
-import org.omg.PortableInterceptor.RequestInfo;
 
 import java.io.IOException;
 import java.util.*;
@@ -364,13 +362,13 @@ public abstract class ValueSourceParser 
     addParser(new DoubleParser("rad") {
       @Override
       public double func(int doc, FunctionValues vals) {
-        return vals.doubleVal(doc) * DistanceUtils.DEGREES_TO_RADIANS;
+        return Math.toRadians(vals.doubleVal(doc));
       }
     });
     addParser(new DoubleParser("deg") {
       @Override
       public double func(int doc, FunctionValues vals) {
-        return vals.doubleVal(doc) * DistanceUtils.RADIANS_TO_DEGREES;
+        return Math.toDegrees(vals.doubleVal(doc));
       }
     });
     addParser(new DoubleParser("sqrt") {

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashFunction.java Tue Mar 13 23:28:17 2012
@@ -19,7 +19,7 @@ package org.apache.solr.search.function.
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.spatial.geohash.GeoHashUtils;
+import com.spatial4j.core.util.GeohashUtils;
 
 import java.util.Map;
 import java.io.IOException;
@@ -55,7 +55,7 @@ public class GeohashFunction extends Val
 
       @Override
       public String strVal(int doc) {
-        return GeoHashUtils.encode(latDV.doubleVal(doc), lonDV.doubleVal(doc));
+        return GeohashUtils.encodeLatLon(latDV.doubleVal(doc), lonDV.doubleVal(doc));
       }
 
       @Override

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java Tue Mar 13 23:28:17 2012
@@ -20,10 +20,15 @@ package org.apache.solr.search.function.
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
-import org.apache.lucene.spatial.DistanceUtils;
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.spatial.geohash.GeoHashUtils;
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.context.simple.SimpleSpatialContext;
+import com.spatial4j.core.distance.DistanceCalculator;
+import com.spatial4j.core.distance.DistanceUnits;
+import com.spatial4j.core.distance.GeodesicSphereDistCalc;
+import com.spatial4j.core.util.GeohashUtils;
+import com.spatial4j.core.shape.Point;
 
 import java.util.Map;
 import java.io.IOException;
@@ -43,11 +48,14 @@ public class GeohashHaversineFunction ex
 
   private ValueSource geoHash1, geoHash2;
   private double radius;
+  private final SpatialContext ctx;
 
   public GeohashHaversineFunction(ValueSource geoHash1, ValueSource geoHash2, double radius) {
     this.geoHash1 = geoHash1;
     this.geoHash2 = geoHash2;
     this.radius = radius;
+    DistanceCalculator distCalc = new GeodesicSphereDistCalc.Haversine(radius);
+    this.ctx = new SimpleSpatialContext(DistanceUnits.KILOMETERS,distCalc,null);
   }
 
   protected String name() {
@@ -82,10 +90,9 @@ public class GeohashHaversineFunction ex
     if (h1 != null && h2 != null && h1.equals(h2) == false){
       //TODO: If one of the hashes is a literal value source, seems like we could cache it
       //and avoid decoding every time
-      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);
+      Point p1 = GeohashUtils.decode(h1,ctx);
+      Point p2 = GeohashUtils.decode(h2,ctx);
+      result = ctx.getDistCalc().distance(p1, p2);
     } else if (h1 == null || h2 == null){
       result = Double.MAX_VALUE;
     }

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java Tue Mar 13 23:28:17 2012
@@ -26,13 +26,13 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.VectorValueSource;
 import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.spatial.DistanceUtils;
-import org.apache.lucene.spatial.tier.InvalidGeoException;
+import com.spatial4j.core.context.ParseUtils;
+import com.spatial4j.core.distance.DistanceUtils;
+import com.spatial4j.core.exception.InvalidShapeException;
 import org.apache.solr.common.params.SpatialParams;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.FunctionQParser;
 import org.apache.solr.search.ValueSourceParser;
-import org.apache.solr.search.function.*;
 
 import java.io.IOException;
 import java.util.Arrays;
@@ -144,8 +144,8 @@ public class HaversineConstFunction exte
     if (pt == null) return null;
     double[] point = null;
     try {
-      point = DistanceUtils.parseLatitudeLongitude(pt);
-    } catch (InvalidGeoException e) {
+      point = ParseUtils.parseLatitudeLongitude(pt);
+    } catch (InvalidShapeException e) {
       throw new ParseException("Bad spatial pt:" + pt);
     }
     return new VectorValueSource(Arrays.<ValueSource>asList(new DoubleConstValueSource(point[0]),new DoubleConstValueSource(point[1])));
@@ -190,7 +190,7 @@ public class HaversineConstFunction exte
     this.p2 = vs;
     this.latSource = p2.getSources().get(0);
     this.lonSource = p2.getSources().get(1);
-    this.latCenterRad_cos = Math.cos(latCenter * DistanceUtils.DEGREES_TO_RADIANS);
+    this.latCenterRad_cos = Math.cos(Math.toRadians(latCenter));
   }
 
   protected String name() {
@@ -201,15 +201,15 @@ public class HaversineConstFunction exte
   public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final FunctionValues latVals = latSource.getValues(context, readerContext);
     final FunctionValues lonVals = lonSource.getValues(context, readerContext);
-    final double latCenterRad = this.latCenter * DistanceUtils.DEGREES_TO_RADIANS;
-    final double lonCenterRad = this.lonCenter * DistanceUtils.DEGREES_TO_RADIANS;
+    final double latCenterRad = Math.toRadians(this.latCenter);
+    final double lonCenterRad = Math.toRadians(this.lonCenter);
     final double latCenterRad_cos = this.latCenterRad_cos;
 
     return new DoubleDocValues(this) {
       @Override
       public double doubleVal(int doc) {
-        double latRad = latVals.doubleVal(doc) * DistanceUtils.DEGREES_TO_RADIANS;
-        double lonRad = lonVals.doubleVal(doc) * DistanceUtils.DEGREES_TO_RADIANS;
+        double latRad = Math.toRadians(latVals.doubleVal(doc));
+        double lonRad = Math.toRadians(lonVals.doubleVal(doc));
         double diffX = latCenterRad - latRad;
         double diffY = lonCenterRad - lonRad;
         double hsinX = Math.sin(diffX * 0.5);

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java Tue Mar 13 23:28:17 2012
@@ -22,7 +22,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.queries.function.valuesource.MultiValueSource;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.spatial.DistanceUtils;
+import com.spatial4j.core.distance.DistanceUtils;
 import org.apache.solr.common.SolrException;
 
 import java.io.IOException;
@@ -81,17 +81,17 @@ public class HaversineFunction extends V
     double y2;
     double x2;
     if (convertToRadians) {
-      y1 = p1D[0] * DistanceUtils.DEGREES_TO_RADIANS;
-      x1 = p1D[1] * DistanceUtils.DEGREES_TO_RADIANS;
-      y2 = p2D[0] * DistanceUtils.DEGREES_TO_RADIANS;
-      x2 = p2D[1] * DistanceUtils.DEGREES_TO_RADIANS;
+      y1 = Math.toRadians(p1D[0]);
+      x1 = Math.toRadians(p1D[1]);
+      y2 = Math.toRadians(p2D[0]);
+      x2 = Math.toRadians(p2D[1]);
     } else {
       y1 = p1D[0];
       x1 = p1D[1];
       y2 = p2D[0];
       x2 = p2D[1];
     }
-    return DistanceUtils.haversine(y1, x1, y2, x2, radius);
+    return DistanceUtils.distHaversineRAD(y1,x1,y2,x2)*radius;
   }
 
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/SquaredEuclideanFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/SquaredEuclideanFunction.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/SquaredEuclideanFunction.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/SquaredEuclideanFunction.java Tue Mar 13 23:28:17 2012
@@ -18,8 +18,7 @@ package org.apache.solr.search.function.
 
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.valuesource.MultiValueSource;
-import org.apache.lucene.spatial.DistanceUtils;
-
+import com.spatial4j.core.distance.DistanceUtils;
 
 /**
  * While not strictly a distance, the Sq. Euclidean Distance is often all that is needed in many applications
@@ -50,7 +49,7 @@ public class SquaredEuclideanFunction ex
     dv1.doubleVal(doc, vals1);
     dv2.doubleVal(doc, vals2);
 
-    return DistanceUtils.squaredEuclideanDistance(vals1, vals2);
+    return DistanceUtils.distSquaredCartesian(vals1, vals2);
   }
 
   @Override

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java Tue Mar 13 23:28:17 2012
@@ -22,7 +22,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.queries.function.valuesource.MultiValueSource;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.spatial.DistanceUtils;
+import com.spatial4j.core.distance.DistanceUtils;
 import org.apache.solr.common.SolrException;
 
 import java.io.IOException;

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java?rev=1300409&r1=1300408&r2=1300409&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/distance/DistanceFunctionTest.java Tue Mar 13 23:28:17 2012
@@ -16,8 +16,8 @@ package org.apache.solr.search.function.
  * limitations under the License.
  */
 
-import org.apache.lucene.spatial.DistanceUtils;
-import org.apache.lucene.spatial.geohash.GeoHashUtils;
+import com.spatial4j.core.distance.DistanceUtils;
+import com.spatial4j.core.util.GeohashUtils;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
 import org.junit.BeforeClass;
@@ -36,12 +36,12 @@ public class DistanceFunctionTest extend
   @Test
   public void testHaversine() throws Exception {
     clearIndex();
-    assertU(adoc("id", "1", "x_td", "0", "y_td", "0", "gh_s1", GeoHashUtils.encode(32.7693246, -79.9289094)));
-    assertU(adoc("id", "2", "x_td", "0", "y_td", String.valueOf(Math.PI / 2), "gh_s1", GeoHashUtils.encode(32.7693246, -78.9289094)));
-    assertU(adoc("id", "3", "x_td", String.valueOf(Math.PI / 2), "y_td", String.valueOf(Math.PI / 2), "gh_s1", GeoHashUtils.encode(32.7693246, -80.9289094)));
-    assertU(adoc("id", "4", "x_td", String.valueOf(Math.PI / 4), "y_td", String.valueOf(Math.PI / 4), "gh_s1", GeoHashUtils.encode(32.7693246, -81.9289094)));
+    assertU(adoc("id", "1", "x_td", "0", "y_td", "0", "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -79.9289094)));
+    assertU(adoc("id", "2", "x_td", "0", "y_td", String.valueOf(Math.PI / 2), "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -78.9289094)));
+    assertU(adoc("id", "3", "x_td", String.valueOf(Math.PI / 2), "y_td", String.valueOf(Math.PI / 2), "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -80.9289094)));
+    assertU(adoc("id", "4", "x_td", String.valueOf(Math.PI / 4), "y_td", String.valueOf(Math.PI / 4), "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -81.9289094)));
     assertU(adoc("id", "5", "x_td", "45.0", "y_td", "45.0",
-            "gh_s1", GeoHashUtils.encode(32.7693246, -81.9289094)));
+            "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -81.9289094)));
     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());
@@ -56,17 +56,19 @@ public class DistanceFunctionTest extend
     
     //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_s1, \"" + GeoHashUtils.encode(32, -79) +
-            "\",)", "fq", "id:1"), "//float[@name='score']='122.171875'");
+    //note: using assertJQ because it supports numeric deltas, and by default too
+    assertJQ(req("fl", "*,score", "q", "{!func}ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", gh_s1, \"" + GeohashUtils.encodeLatLon(32, -79) + "\",)", "fq", "id:1"),
+        "/response/docs/[0]/score==122.171875");
 
-    assertQ(req("fl", "id,point_hash,score", "q", "{!func}recip(ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", point_hash, \"" + GeoHashUtils.encode(32, -79) + "\"), 1, 1, 0)"),
+    assertQ(req("fl", "id,point_hash,score", "q", "{!func}recip(ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", point_hash, \"" + GeohashUtils.encodeLatLon(32, -79) + "\"), 1, 1, 0)"),
             "//*[@numFound='7']", 
             "//result/doc[1]/str[@name='id'][.='6']",
             "//result/doc[2]/str[@name='id'][.='7']"//all the rest don't matter
             );
 
 
-    assertQ(req("fl", "*,score", "q", "{!func}ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", gh_s1, geohash(32, -79))", "fq", "id:1"), "//float[@name='score']='122.171875'");
+    assertJQ(req("fl", "*,score", "q", "{!func}ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", gh_s1, geohash(32, -79))", "fq", "id:1"),
+        "/response/docs/[0]/score==122.171875");
 
   }