lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pj...@apache.org
Subject svn commit: r769639 - in /lucene/java/trunk/contrib/spatial/src: java/org/apache/lucene/spatial/ java/org/apache/lucene/spatial/geohash/ java/org/apache/lucene/spatial/tier/ test/org/apache/lucene/spatial/tier/
Date Wed, 29 Apr 2009 03:53:22 GMT
Author: pjaol
Date: Wed Apr 29 03:53:21 2009
New Revision: 769639

URL: http://svn.apache.org/viewvc?rev=769639&view=rev
Log:
Fixed bug caused by multiSegmentIndexReader

Modified:
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/SerialChainFilter.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geohash/GeoHashDistanceFilter.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/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.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/SerialChainFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/SerialChainFilter.java?rev=769639&r1=769638&r2=769639&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/SerialChainFilter.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/SerialChainFilter.java
Wed Apr 29 03:53:21 2009
@@ -88,6 +88,7 @@
      */
     if (actionType[i] == AND){
        try {
+      	//System.out.println(chain[i] );
         bits = (BitSet) ((DocIdBitSet)chain[i].getDocIdSet(reader)).getBitSet().clone();
       } catch (IOException e) {
         // TODO Auto-generated catch block
@@ -97,9 +98,9 @@
     }
     
     for( ; i < chainSize; i++) {
-    
+    	
       int action = (i < actionSize)? actionType[i]: DEFAULT;
-    
+      //System.out.println(chain[i] + ": "+  action);
       switch (action){
       
       case (SERIALAND):
@@ -132,6 +133,10 @@
         break;
       }
     }
+    
+//    System.out.println("++++++====================");
+//    new Exception().printStackTrace();
+    
     return new DocIdBitSet(bits);
   }
 

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geohash/GeoHashDistanceFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geohash/GeoHashDistanceFilter.java?rev=769639&r1=769638&r2=769639&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geohash/GeoHashDistanceFilter.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geohash/GeoHashDistanceFilter.java
Wed Apr 29 03:53:21 2009
@@ -48,6 +48,8 @@
   
   private Map<Integer,Double> distances = null;
   private Precision precise = null;
+  int offset = 0; 
+  int nextOffset;
   
   /**
    * Provide a distance filter based from a center point with a radius
@@ -143,7 +145,9 @@
     
 
     /* store calculated distances for reuse by other components */
-    distances = new HashMap<Integer,Double>(size);
+    offset += reader.maxDoc();
+    if (distances == null)
+    	distances = new HashMap<Integer,Double>(size);
     
     long start = System.currentTimeMillis();
     String[] geoHashCache = FieldCache.DEFAULT.getStrings(reader, geoHashField);
@@ -194,7 +198,7 @@
   
 
     cdistance = null;
-    
+    nextOffset += offset;
     return result;
   }
 

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=769639&r1=769638&r2=769639&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
Wed Apr 29 03:53:21 2009
@@ -138,9 +138,9 @@
     return new SerialChainFilter(f,chain); 
   }
     
-  public Query getQuery() {
-      return new ConstantScoreQuery(getFilter());
-  }
+//  public Query getQuery() {
+//      return new ConstantScoreQuery(getFilter());
+//  }
 
   
   public Query getQuery(Query query){

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=769639&r1=769638&r2=769639&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
Wed Apr 29 03:53:21 2009
@@ -75,11 +75,15 @@
 //      if (this.distances == null) {
 //          distances = distanceFilter.getDistances();
 //      }
-      double a = distanceFilter.getDistance(aDoc.doc);
-      double b = distanceFilter.getDistance(bDoc.doc);
-      if (a > b) return 1;
-      if (a < b )return -1;
-      
+    	//System.out.println("comparing : "+ aDoc.doc+ " - "+ bDoc.doc);
+    	try {
+    		double a = distanceFilter.getDistance(aDoc.doc);
+    		double b = distanceFilter.getDistance(bDoc.doc);
+    		if (a > b) return 1;
+    		if (a < b )return -1;
+    	} catch (Exception e){
+    		System.out.println(" Failed with sort with "+ aDoc.doc +" - "+bDoc.doc);
+    	}
       return 0;
     }
 

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=769639&r1=769638&r2=769639&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
Wed Apr 29 03:53:21 2009
@@ -45,6 +45,8 @@
   String latField;
   String lngField;
   Logger log = Logger.getLogger(getClass().getName());
+  int offset =0;
+  int nextOffset = 0;
   
   Map<Integer,Double> distances = null;
   private Precision precise = null;
@@ -134,17 +136,24 @@
 
   
     /* Create a BitSet to store the result */
+  	
     int size = bits.cardinality();
     BitSet result = new BitSet(size);
     
-
+    
     /* create an intermediate cache to avoid recomputing
          distances for the same point  */
     HashMap<String,Double> cdistance = new HashMap<String,Double>(size);
     
 
     /* store calculated distances for reuse by other components */
-    distances = new HashMap<Integer,Double>(size);
+    boolean db = false;
+    offset += reader.maxDoc();
+    if (distances == null){
+    	distances = new HashMap<Integer,Double>();
+    }else {
+    	db=true;
+    }
     
     long start = System.currentTimeMillis();
     String[] latIndex = FieldCache.DEFAULT.getStrings(reader, latField);
@@ -181,10 +190,10 @@
         cdistance.put(ck, d);
       }
       
-      distances.put(i, d);
-        
+      // why was i storing all distances again?
       if (d < distance){
         result.set(i);
+        distances.put(i+ nextOffset, d); // include nextOffset for multireader  
       }
       i = bits.nextSetBit(i+1);
     }
@@ -197,6 +206,7 @@
   
 
     cdistance = null;
+    nextOffset += offset;  // this should be something that's part of indexReader
     
     return result;
   }

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=769639&r1=769638&r2=769639&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
Wed Apr 29 03:53:21 2009
@@ -202,10 +202,10 @@
     System.out.println("Distance Filter filtered: " + distances.size());
     System.out.println("Results: " + results);
     System.out.println("=============================");
-    System.out.println("Distances should be 14 "+ distances.size());
+    System.out.println("Distances should be 7 "+ distances.size());
     System.out.println("Results should be 7 "+ results);
 
-    assertEquals(14, distances.size());
+    assertEquals(7, distances.size()); // fixed a store of only needed distances
     assertEquals(7, results);
     double lastDistance = 0;
     for(int i =0 ; i < results; i++){



Mime
View raw message