mirror of https://github.com/apache/lucene.git
LUCENE-7099: improve test to exercise searchAfter
This commit is contained in:
parent
5d7592bc14
commit
ae866b0149
|
@ -27,7 +27,6 @@ import org.apache.lucene.search.MatchAllDocsQuery;
|
||||||
import org.apache.lucene.search.Sort;
|
import org.apache.lucene.search.Sort;
|
||||||
import org.apache.lucene.search.SortField;
|
import org.apache.lucene.search.SortField;
|
||||||
import org.apache.lucene.search.TopDocs;
|
import org.apache.lucene.search.TopDocs;
|
||||||
import org.apache.lucene.search.TopFieldDocs;
|
|
||||||
import org.apache.lucene.spatial.util.GeoDistanceUtils;
|
import org.apache.lucene.spatial.util.GeoDistanceUtils;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
|
@ -59,7 +58,7 @@ public class TestLatLonPointDistanceSort extends LuceneTestCase {
|
||||||
iw.close();
|
iw.close();
|
||||||
|
|
||||||
Sort sort = new Sort(LatLonPoint.newDistanceSort("location", 40.7143528, -74.0059731));
|
Sort sort = new Sort(LatLonPoint.newDistanceSort("location", 40.7143528, -74.0059731));
|
||||||
TopFieldDocs td = searcher.search(new MatchAllDocsQuery(), 3, sort);
|
TopDocs td = searcher.search(new MatchAllDocsQuery(), 3, sort);
|
||||||
|
|
||||||
FieldDoc d = (FieldDoc) td.scoreDocs[0];
|
FieldDoc d = (FieldDoc) td.scoreDocs[0];
|
||||||
assertEquals(462.61748421408186D, (Double)d.fields[0], 0.0D);
|
assertEquals(462.61748421408186D, (Double)d.fields[0], 0.0D);
|
||||||
|
@ -130,6 +129,11 @@ public class TestLatLonPointDistanceSort extends LuceneTestCase {
|
||||||
if (id != other.id) return false;
|
if (id != other.id) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Result [id=" + id + ", distance=" + distance + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doRandomTest(int numDocs, int numQueries) throws IOException {
|
private void doRandomTest(int numDocs, int numQueries) throws IOException {
|
||||||
|
@ -182,6 +186,17 @@ public class TestLatLonPointDistanceSort extends LuceneTestCase {
|
||||||
Result actual = new Result((Integer) fieldDoc.fields[1], (Double) fieldDoc.fields[0]);
|
Result actual = new Result((Integer) fieldDoc.fields[1], (Double) fieldDoc.fields[0]);
|
||||||
assertEquals(expected[resultNumber], actual);
|
assertEquals(expected[resultNumber], actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get page2 with searchAfter()
|
||||||
|
if (topN < reader.maxDoc()) {
|
||||||
|
int page2 = TestUtil.nextInt(random(), 1, reader.maxDoc() - topN);
|
||||||
|
TopDocs topDocs2 = searcher.searchAfter(topDocs.scoreDocs[topN - 1], new MatchAllDocsQuery(), page2, sort);
|
||||||
|
for (int resultNumber = 0; resultNumber < page2; resultNumber++) {
|
||||||
|
FieldDoc fieldDoc = (FieldDoc) topDocs2.scoreDocs[resultNumber];
|
||||||
|
Result actual = new Result((Integer) fieldDoc.fields[1], (Double) fieldDoc.fields[0]);
|
||||||
|
assertEquals(expected[topN + resultNumber], actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
Loading…
Reference in New Issue