mirror of https://github.com/apache/lucene.git
LUCENE-1571: fix LatLongDistanceFilter to respect deleted docs
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@784576 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6671c43458
commit
26b9dea62b
|
@ -25,6 +25,7 @@ import java.util.WeakHashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
|
import org.apache.lucene.index.TermDocs;
|
||||||
import org.apache.lucene.search.FieldCache;
|
import org.apache.lucene.search.FieldCache;
|
||||||
import org.apache.lucene.spatial.NumberUtils;
|
import org.apache.lucene.spatial.NumberUtils;
|
||||||
import org.apache.lucene.spatial.tier.DistanceHandler.Precision;
|
import org.apache.lucene.spatial.tier.DistanceHandler.Precision;
|
||||||
|
@ -96,15 +97,16 @@ public class LatLongDistanceFilter extends DistanceFilter {
|
||||||
/* 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){
|
if (distances == null){
|
||||||
distances = new HashMap<Integer,Double>();
|
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 sx = latIndex[doc];
|
||||||
String sy = lngIndex[i];
|
String sy = lngIndex[doc];
|
||||||
|
|
||||||
double x = NumberUtils.SortableStr2double(sx);
|
double x = NumberUtils.SortableStr2double(sx);
|
||||||
double y = NumberUtils.SortableStr2double(sy);
|
double y = NumberUtils.SortableStr2double(sy);
|
||||||
|
@ -125,15 +127,12 @@ public class LatLongDistanceFilter extends DistanceFilter {
|
||||||
d = DistanceUtils.getInstance().getDistanceMi(lat, lng, x, y);
|
d = DistanceUtils.getInstance().getDistanceMi(lat, lng, x, y);
|
||||||
cdistance.put(ck, d);
|
cdistance.put(ck, d);
|
||||||
}
|
}
|
||||||
distances.put(i, d);
|
|
||||||
|
|
||||||
// why was i storing all distances again?
|
// why was i storing all distances again?
|
||||||
if (d < distance){
|
if (d < distance){
|
||||||
bits.set(i);
|
bits.set(doc);
|
||||||
distances.put(i+ nextOffset, d); // include nextOffset for multi segment reader
|
distances.put(doc+ nextOffset, d); // include nextOffset for multi segment reader
|
||||||
}
|
}
|
||||||
i = bits.nextSetBit(i+1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
int size = bits.cardinality();
|
int size = bits.cardinality();
|
||||||
nextOffset += reader.maxDoc(); // this should be something that's part of indexReader
|
nextOffset += reader.maxDoc(); // this should be something that's part of indexReader
|
||||||
|
@ -175,6 +174,12 @@ public class LatLongDistanceFilter extends DistanceFilter {
|
||||||
/* loop over all set bits (hits from the boundary box filters) */
|
/* loop over all set bits (hits from the boundary box filters) */
|
||||||
int i = bits.nextSetBit(0);
|
int i = bits.nextSetBit(0);
|
||||||
while (i >= 0){
|
while (i >= 0){
|
||||||
|
|
||||||
|
if (reader.isDeleted(i)) {
|
||||||
|
i = bits.nextSetBit(i+1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
double x,y;
|
double x,y;
|
||||||
|
|
||||||
// if we have a completed
|
// if we have a completed
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.lucene.spatial.tier;
|
package org.apache.lucene.spatial.tier;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.BitSet;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
@ -24,8 +25,12 @@ import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
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.search.IndexSearcher;
|
||||||
import org.apache.lucene.spatial.NumberUtils;
|
import org.apache.lucene.spatial.NumberUtils;
|
||||||
|
import org.apache.lucene.spatial.tier.LatLongDistanceFilter;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,16 +47,20 @@ public class TestDistance extends TestCase{
|
||||||
private double lng= -77.386398;
|
private double lng= -77.386398;
|
||||||
private String latField = "lat";
|
private String latField = "lat";
|
||||||
private String lngField = "lng";
|
private String lngField = "lng";
|
||||||
|
private IndexWriter writer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws IOException {
|
protected void setUp() throws IOException {
|
||||||
directory = new RAMDirectory();
|
directory = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
||||||
addData(writer);
|
addData(writer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws IOException {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
private void addPoint(IndexWriter writer, String name, double lat, double lng) throws IOException{
|
private void addPoint(IndexWriter writer, String name, double lat, double lng) throws IOException{
|
||||||
|
|
||||||
|
@ -91,6 +100,17 @@ public class TestDistance extends TestCase{
|
||||||
writer.flush();
|
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() {
|
public void testMiles() {
|
||||||
|
|
Loading…
Reference in New Issue