lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pj...@apache.org
Subject svn commit: r762801 - in /lucene/java/trunk/contrib/spatial/src: java/org/apache/lucene/spatial/tier/ test/org/apache/lucene/spatial/tier/
Date Tue, 07 Apr 2009 14:54:50 GMT
Author: pjaol
Date: Tue Apr  7 14:54:50 2009
New Revision: 762801

URL: http://svn.apache.org/viewvc?rev=762801&view=rev
Log:
Commit LUCENE-1588 DistanceFieldComparatorSource
deprecate BoundaryBoxFilter

Added:
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java
Modified:
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java
    lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java?rev=762801&r1=762800&r2=762801&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java
Tue Apr  7 14:54:50 2009
@@ -33,7 +33,8 @@
 /**
  * An implementation of org.apache.lucene.search.RangeFilter that
  * caches values extracted from the index.
- * 
+ * @deprecated
+ * @see CartesianShapeFilter
  */
 public class BoundaryBoxFilter extends Filter {
 

Added: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java?rev=762801&view=auto
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java
(added)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java
Tue Apr  7 14:54:50 2009
@@ -0,0 +1,130 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.spatial.tier;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.FieldComparatorSource;
+import org.apache.lucene.search.SortField;
+
+public class DistanceFieldComparatorSource extends FieldComparatorSource {
+
+	private static final long serialVersionUID = 1L;
+
+	private DistanceFilter distanceFilter;
+	private DistanceScoreDocLookupComparator dsdlc;
+
+	public DistanceFieldComparatorSource(Filter distanceFilter) {
+
+		this.distanceFilter = (DistanceFilter) distanceFilter;
+
+	}
+
+	public void cleanUp() {
+		distanceFilter = null;
+
+		if (dsdlc != null)
+			dsdlc.cleanUp();
+
+		dsdlc = null;
+	}
+
+	@Override
+	public FieldComparator newComparator(String fieldname,
+			IndexReader[] subReaders, int numHits, int sortPos, boolean reversed)
+			throws IOException {
+		dsdlc = new DistanceScoreDocLookupComparator(distanceFilter, numHits);
+		return dsdlc;
+	}
+
+	private class DistanceScoreDocLookupComparator extends FieldComparator {
+
+		private DistanceFilter distanceFilter;
+		private double[] values;
+		private double bottom;
+
+		public DistanceScoreDocLookupComparator(DistanceFilter distanceFilter, int numHits) {
+			this.distanceFilter = distanceFilter;
+			values = new double[numHits];
+			return;
+		}
+
+		@Override
+		public int compare(int slot1, int slot2) {
+			double a = values[slot1];
+			double b = values[slot2];
+			if (a > b)
+				return 1;
+			if (a < b)
+				return -1;
+
+			return 0;
+		}
+
+	
+
+		public void cleanUp() {
+			distanceFilter = null;
+		}
+
+		@Override
+		public int compareBottom(int doc, float score) {
+			final double v2 = distanceFilter.getDistance(doc);
+      if (bottom > v2) {
+        return 1;
+      } else if (bottom < v2) {
+        return -1;
+      } 
+			return 0;
+		}
+
+		@Override
+		public void copy(int slot, int doc, float score) {
+			values[slot] = distanceFilter.getDistance(doc);
+		}
+
+		@Override
+		public void setBottom(int slot) {
+			this.bottom = values[slot];
+
+		}
+
+		@Override
+		public void setNextReader(IndexReader reader, int docBase, int numSlotsFull)
+				throws IOException {
+			// TODO Auto-generated method stub
+
+		}
+
+		@Override
+		public Comparable<Double> value(int slot) {
+			return values[slot];
+		}
+
+		@Override
+		public int sortType() {
+			
+			return SortField.DOUBLE;
+		}
+	}
+
+}

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java?rev=762801&r1=762800&r2=762801&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java
Tue Apr  7 14:54:50 2009
@@ -142,6 +142,11 @@
       return new ConstantScoreQuery(getFilter());
   }
 
+  
+  public Query getQuery(Query query){
+  	return new ConstantScoreQuery(getFilter(query));
+  }
+  
   public double getLat() {
     return lat;
   }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java?rev=762801&r1=762800&r2=762801&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java
Tue Apr  7 14:54:50 2009
@@ -26,6 +26,11 @@
 import org.apache.lucene.search.SortComparatorSource;
 import org.apache.lucene.search.SortField;
 
+/**
+ * 
+ * @deprecated
+ * @see DistanceFieldComparatorSource
+ */
 public class DistanceSortSource implements SortComparatorSource {
 
   private static final long serialVersionUID = 1L;

Modified: lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java?rev=762801&r1=762800&r2=762801&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
Tue Apr  7 14:54:50 2009
@@ -138,9 +138,9 @@
     addPoint(writer,"Iota Club and Cafe",38.8890000,-77.0923000);
     addPoint(writer,"Hilton Washington Embassy Row",38.9103000,-77.0451000);
     addPoint(writer,"HorseFeathers, Bar & Grill", 39.01220000000001, -77.3942);
-    writer.flush();
+   
     writer.commit();
-    //writer.close();
+    writer.close();
   }
   
   public void testRange() throws IOException, InvalidGeoException {
@@ -179,12 +179,12 @@
     // As the radius filter has performed the distance calculations
     // already, pass in the filter to reuse the results.
     // 
-    DistanceSortSource dsort = new DistanceSortSource(dq.distanceFilter);
-    Sort sort = new Sort(new SortField("foo", dsort));
+    DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
+    Sort sort = new Sort(new SortField("foo", dsort,false));
     
     // Perform the search, using the term query, the serial chain filter, and the
     // distance sort
-    Hits hits = searcher.search(customScore, dq.getFilter()); //,sort);
+    Hits hits = searcher.search(customScore, dq.getFilter(),sort);
 
     int results = hits.length();
     
@@ -206,7 +206,7 @@
 
     assertEquals(14, distances.size());
     assertEquals(7, results);
-    
+    double lastDistance = 0;
     for(int i =0 ; i < results; i++){
       Document d = hits.doc(i);
       
@@ -217,9 +217,11 @@
       
       double distance = DistanceUtils.getInstance().getDistanceMi(lat, lng, rsLat, rsLng);
       double llm = DistanceUtils.getInstance().getLLMDistance(lat, lng, rsLat, rsLng);
-      System.out.println("Name: "+ name +", Distance (res, ortho, harvesine):"+ distance
+" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i));
+      System.out.println("Name: "+ name +", Distance "+ distance); //(res, ortho, harvesine):"+
distance +" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i));
       assertTrue(Math.abs((distance - llm)) < 1);
       assertTrue((distance < miles ));
+      assertTrue(geo_distance > lastDistance);
+      lastDistance = geo_distance;
     }
   }
   
@@ -302,6 +304,7 @@
 	      System.out.println("Name: "+ name +", Distance (res, ortho, harvesine):"+ distance
+" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i));
 	      assertTrue(Math.abs((distance - llm)) < 1);
 	      assertTrue((distance < miles ));
+	      
 	    }
 	  }
   



Mime
View raw message