Fixed doc id's to bitset id for sorting with a multi segmented index FieldSourceComparator still uses bitset id's

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@783517 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick O'Leary 2009-06-10 20:59:26 +00:00
parent eb6fbfa3d5
commit 5509306e40
3 changed files with 50 additions and 30 deletions

View File

@ -51,7 +51,7 @@ public class CartesianShapeFilter extends Filter {
TermDocs termDocs = reader.termDocs(); TermDocs termDocs = reader.termDocs();
List<Double> area = shape.getArea(); List<Double> area = shape.getArea();
int sz = area.size(); int sz = area.size();
log.info("Area size "+ sz); log.fine("Area size "+ sz);
// iterate through each boxid // iterate through each boxid
for (int i =0; i< sz; i++) { for (int i =0; i< sz; i++) {
@ -68,7 +68,7 @@ public class CartesianShapeFilter extends Filter {
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
log.info("BoundaryBox Time Taken: "+ (end - start) + " found: "+bits.cardinality()+" candidates"); log.fine("BoundaryBox Time Taken: "+ (end - start) + " found: "+bits.cardinality()+" candidates");
return bits; return bits;
} }

View File

@ -48,8 +48,8 @@ public class DistanceFieldComparatorSource extends FieldComparatorSource {
} }
@Override @Override
public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) public FieldComparator newComparator(String fieldname, int numHits,
throws IOException { int sortPos, boolean reversed) throws IOException {
dsdlc = new DistanceScoreDocLookupComparator(distanceFilter, numHits); dsdlc = new DistanceScoreDocLookupComparator(distanceFilter, numHits);
return dsdlc; return dsdlc;
} }
@ -59,8 +59,10 @@ public class DistanceFieldComparatorSource extends FieldComparatorSource {
private DistanceFilter distanceFilter; private DistanceFilter distanceFilter;
private double[] values; private double[] values;
private double bottom; private double bottom;
private int offset =0;
public DistanceScoreDocLookupComparator(DistanceFilter distanceFilter, int numHits) {
public DistanceScoreDocLookupComparator(DistanceFilter distanceFilter,
int numHits) {
this.distanceFilter = distanceFilter; this.distanceFilter = distanceFilter;
values = new double[numHits]; values = new double[numHits];
return; return;
@ -78,26 +80,25 @@ public class DistanceFieldComparatorSource extends FieldComparatorSource {
return 0; return 0;
} }
public void cleanUp() { public void cleanUp() {
distanceFilter = null; distanceFilter = null;
} }
@Override @Override
public int compareBottom(int doc) { public int compareBottom(int doc) {
final double v2 = distanceFilter.getDistance(doc); double v2 = distanceFilter.getDistance(doc+ offset);
if (bottom > v2) {
return 1; if (bottom > v2) {
} else if (bottom < v2) { return 1;
return -1; } else if (bottom < v2) {
} return -1;
}
return 0; return 0;
} }
@Override @Override
public void copy(int slot, int doc) { public void copy(int slot, int doc) {
values[slot] = distanceFilter.getDistance(doc); values[slot] = distanceFilter.getDistance(doc + offset);
} }
@Override @Override
@ -107,10 +108,12 @@ public class DistanceFieldComparatorSource extends FieldComparatorSource {
} }
@Override @Override
public void setNextReader(IndexReader reader, int docBase, int numSlotsFull) public void setNextReader(IndexReader reader, int docBase,
throws IOException { int numSlotsFull) throws IOException {
// TODO Auto-generated method stub
// each reader in a segmented base
// has an offset based on the maxDocs of previous readers
offset = docBase;
} }
@Override @Override
@ -120,7 +123,7 @@ public class DistanceFieldComparatorSource extends FieldComparatorSource {
@Override @Override
public int sortType() { public int sortType() {
return SortField.DOUBLE; return SortField.DOUBLE;
} }
} }

View File

@ -45,7 +45,7 @@ public class LatLongDistanceFilter extends DistanceFilter {
String latField; String latField;
String lngField; String lngField;
Logger log = Logger.getLogger(getClass().getName()); Logger log = Logger.getLogger(getClass().getName());
int offset =0;
int nextOffset = 0; int nextOffset = 0;
Map<Integer,Double> distances = null; Map<Integer,Double> distances = null;
@ -89,12 +89,18 @@ public class LatLongDistanceFilter extends DistanceFilter {
// distances for the same point // distances for the same point
// TODO: Why is this a WeakHashMap? // TODO: Why is this a WeakHashMap?
WeakHashMap<String,Double> cdistance = new WeakHashMap<String,Double>(maxdocs); WeakHashMap<String,Double> cdistance = new WeakHashMap<String,Double>(maxdocs);
long start = System.currentTimeMillis();
String[] latIndex = FieldCache.DEFAULT.getStrings(reader, latField); String[] latIndex = FieldCache.DEFAULT.getStrings(reader, latField);
String[] lngIndex = FieldCache.DEFAULT.getStrings(reader, lngField); String[] lngIndex = FieldCache.DEFAULT.getStrings(reader, lngField);
/* store calculated distances for reuse by other components */ /* store calculated distances for reuse by other components */
distances = new HashMap<Integer,Double>(maxdocs); distances = new HashMap<Integer,Double>(maxdocs);
if (distances == null){
distances = new HashMap<Integer,Double>();
}
for (int i = 0 ; i < maxdocs; i++) { for (int i = 0 ; i < maxdocs; i++) {
String sx = latIndex[i]; String sx = latIndex[i];
@ -121,11 +127,22 @@ public class LatLongDistanceFilter extends DistanceFilter {
} }
distances.put(i, d); distances.put(i, d);
// why was i storing all distances again?
if (d < distance){ if (d < distance){
bits.set(i); bits.set(i);
distances.put(i+ 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
long end = System.currentTimeMillis();
log.fine("Bits 1: Time taken : "+ (end - start) +
", results : "+ distances.size() +
", cached : "+ cdistance.size() +
", incoming size: "+ size+
", nextOffset: "+ nextOffset);
return bits; return bits;
} }
@ -146,13 +163,9 @@ public class LatLongDistanceFilter extends DistanceFilter {
HashMap<String,Double> cdistance = new HashMap<String,Double>(size); HashMap<String,Double> cdistance = new HashMap<String,Double>(size);
/* store calculated distances for reuse by other components */
boolean db = false;
offset += reader.maxDoc();
if (distances == null){ if (distances == null){
distances = new HashMap<Integer,Double>(); distances = new HashMap<Integer,Double>();
}else {
db=true;
} }
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@ -193,20 +206,24 @@ public class LatLongDistanceFilter extends DistanceFilter {
// why was i storing all distances again? // why was i storing all distances again?
if (d < distance){ if (d < distance){
result.set(i); result.set(i);
distances.put(i+ nextOffset, d); // include nextOffset for multireader int did = i + nextOffset;
distances.put(did, d); // include nextOffset for multi segment reader
} }
i = bits.nextSetBit(i+1); i = bits.nextSetBit(i+1);
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
nextOffset += reader.maxDoc(); // this should be something that's part of indexReader
log.fine("Time taken : "+ (end - start) + log.fine("Time taken : "+ (end - start) +
", results : "+ distances.size() + ", results : "+ distances.size() +
", cached : "+ cdistance.size() + ", cached : "+ cdistance.size() +
", incoming size: "+ size); ", incoming size: "+ size+
", nextOffset: "+ nextOffset);
cdistance = null; cdistance = null;
nextOffset += offset; // this should be something that's part of indexReader
return result; return result;
} }