mirror of https://github.com/apache/lucene.git
Fixed bug caused by multiSegmentIndexReader
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@769639 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
888a897063
commit
46619cfa23
|
@ -88,6 +88,7 @@ public class SerialChainFilter extends Filter {
|
|||
*/
|
||||
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 @@ public class SerialChainFilter extends Filter {
|
|||
}
|
||||
|
||||
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 @@ public class SerialChainFilter extends Filter {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// System.out.println("++++++====================");
|
||||
// new Exception().printStackTrace();
|
||||
|
||||
return new DocIdBitSet(bits);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ public class GeoHashDistanceFilter extends DistanceFilter {
|
|||
|
||||
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 @@ public class GeoHashDistanceFilter extends DistanceFilter {
|
|||
|
||||
|
||||
/* 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 @@ public class GeoHashDistanceFilter extends DistanceFilter {
|
|||
|
||||
|
||||
cdistance = null;
|
||||
|
||||
nextOffset += offset;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,9 +138,9 @@ public class DistanceQueryBuilder {
|
|||
return new SerialChainFilter(f,chain);
|
||||
}
|
||||
|
||||
public Query getQuery() {
|
||||
return new ConstantScoreQuery(getFilter());
|
||||
}
|
||||
// public Query getQuery() {
|
||||
// return new ConstantScoreQuery(getFilter());
|
||||
// }
|
||||
|
||||
|
||||
public Query getQuery(Query query){
|
||||
|
|
|
@ -75,11 +75,15 @@ public class DistanceSortSource implements SortComparatorSource {
|
|||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ public class LatLongDistanceFilter extends DistanceFilter {
|
|||
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 @@ public class LatLongDistanceFilter extends DistanceFilter {
|
|||
|
||||
|
||||
/* 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 @@ public class LatLongDistanceFilter extends DistanceFilter {
|
|||
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 @@ public class LatLongDistanceFilter extends DistanceFilter {
|
|||
|
||||
|
||||
cdistance = null;
|
||||
nextOffset += offset; // this should be something that's part of indexReader
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -202,10 +202,10 @@ public class TestCartesian extends TestCase{
|
|||
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++){
|
||||
|
|
Loading…
Reference in New Issue