lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r784576 - in /lucene/java/trunk/contrib/spatial/src: java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java test/org/apache/lucene/spatial/tier/TestDistance.java
Date Sun, 14 Jun 2009 15:47:15 GMT
Author: mikemccand
Date: Sun Jun 14 15:47:15 2009
New Revision: 784576

URL: http://svn.apache.org/viewvc?rev=784576&view=rev
Log:
LUCENE-1571: fix LatLongDistanceFilter to respect deleted docs

Modified:
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java
    lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java?rev=784576&r1=784575&r2=784576&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java
Sun Jun 14 15:47:15 2009
@@ -25,6 +25,7 @@
 import java.util.logging.Logger;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.spatial.NumberUtils;
 import org.apache.lucene.spatial.tier.DistanceHandler.Precision;
@@ -96,15 +97,16 @@
     /* store calculated distances for reuse by other components */
     distances = new HashMap<Integer,Double>(maxdocs);
     
-    
     if (distances == null){
     	distances = new HashMap<Integer,Double>();
     }
-    
-    for (int i = 0 ; i < maxdocs; i++) {
+
+    TermDocs td = reader.termDocs(null);
+    while(td.next()) {
+      int doc = td.doc();
       
-      String sx = latIndex[i];
-      String sy = lngIndex[i];
+      String sx = latIndex[doc];
+      String sy = lngIndex[doc];
   
       double x = NumberUtils.SortableStr2double(sx);
       double y = NumberUtils.SortableStr2double(sy);
@@ -125,15 +127,12 @@
         d = DistanceUtils.getInstance().getDistanceMi(lat, lng, x, y);
         cdistance.put(ck, d);
       }
-      distances.put(i, d);
       
    // why was i storing all distances again?
       if (d < distance){
-        bits.set(i);
-        distances.put(i+ nextOffset, d); // include nextOffset for multi segment reader 

+        bits.set(doc);
+        distances.put(doc+ nextOffset, d); // include nextOffset for multi segment reader
 
       }
-      i = bits.nextSetBit(i+1);
-      
     }
     int size = bits.cardinality();
     nextOffset += reader.maxDoc();  // this should be something that's part of indexReader
@@ -175,6 +174,12 @@
     /* loop over all set bits (hits from the boundary box filters) */
     int i = bits.nextSetBit(0);
     while (i >= 0){
+
+      if (reader.isDeleted(i)) {
+        i = bits.nextSetBit(i+1);
+        continue;
+      }
+
       double x,y;
       
       // if we have a completed

Modified: lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java?rev=784576&r1=784575&r2=784576&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java
Sun Jun 14 15:47:15 2009
@@ -17,6 +17,7 @@
 package org.apache.lucene.spatial.tier;
 
 import java.io.IOException;
+import java.util.BitSet;
 
 import junit.framework.TestCase;
 
@@ -24,8 +25,12 @@
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Filter;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.spatial.NumberUtils;
+import org.apache.lucene.spatial.tier.LatLongDistanceFilter;
 import org.apache.lucene.store.RAMDirectory;
 
 
@@ -42,16 +47,20 @@
   private double lng= -77.386398;
   private String latField = "lat";
   private String lngField = "lng";
-  
+  private IndexWriter writer;
   
   @Override
   protected void setUp() throws IOException {
     directory = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+    writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
     addData(writer);
     
   }
-  
+
+  @Override
+  protected void tearDown() throws IOException {
+    writer.close();
+  }
   
   private void addPoint(IndexWriter writer, String name, double lat, double lng) throws IOException{
     
@@ -90,7 +99,18 @@
     addPoint(writer,"HorseFeathers, Bar & Grill", 39.01220000000001, -77.3942);
     writer.flush();
   }
-  
+
+  public void testLatLongFilterOnDeletedDocs() throws Exception {
+    writer.deleteDocuments(new Term("name", "Potomac"));
+    IndexReader r = writer.getReader();
+    LatLongDistanceFilter f = new LatLongDistanceFilter(lat, lng, 1.0, latField, lngField);
+    f.bits(r);
+
+    BitSet allSet = new BitSet(r.maxDoc());
+    allSet.set(0, r.maxDoc());
+    f.bits(r, allSet);
+    r.close();
+  }
  
   
   public void testMiles() {



Mime
View raw message