LUCENE-5325: Add test for missing values in sorts

This commit is contained in:
Alan Woodward 2016-12-29 14:44:11 +00:00
parent 00723827ff
commit a4335c0e9f
2 changed files with 18 additions and 0 deletions

View File

@ -53,6 +53,8 @@ public class TestDoubleValuesSource extends LuceneTestCase {
document.add(new NumericDocValuesField("long", random().nextLong()));
document.add(new FloatDocValuesField("float", random().nextFloat()));
document.add(new DoubleDocValuesField("double", random().nextDouble()));
if (i == 545)
document.add(new DoubleDocValuesField("onefield", 45.72));
iw.addDocument(document);
}
reader = iw.getReader();
@ -67,6 +69,13 @@ public class TestDoubleValuesSource extends LuceneTestCase {
super.tearDown();
}
public void testSortMissing() throws Exception {
DoubleValuesSource onefield = DoubleValuesSource.fromDoubleField("onefield");
TopDocs results = searcher.search(new MatchAllDocsQuery(), 1, new Sort(onefield.getSortField(true)));
FieldDoc first = (FieldDoc) results.scoreDocs[0];
assertEquals(45.72, first.fields[0]);
}
public void testSimpleFieldEquivalences() throws Exception {
checkSorts(new MatchAllDocsQuery(), new Sort(new SortField("int", SortField.Type.INT, random().nextBoolean())));
checkSorts(new MatchAllDocsQuery(), new Sort(new SortField("long", SortField.Type.LONG, random().nextBoolean())));

View File

@ -49,6 +49,8 @@ public class TestLongValuesSource extends LuceneTestCase {
document.add(newTextField("oddeven", (i % 2 == 0) ? "even" : "odd", Field.Store.NO));
document.add(new NumericDocValuesField("int", random().nextInt()));
document.add(new NumericDocValuesField("long", random().nextLong()));
if (i == 545)
document.add(new NumericDocValuesField("onefield", 45));
iw.addDocument(document);
}
reader = iw.getReader();
@ -63,6 +65,13 @@ public class TestLongValuesSource extends LuceneTestCase {
super.tearDown();
}
public void testSortMissing() throws Exception {
LongValuesSource onefield = LongValuesSource.fromLongField("onefield");
TopDocs results = searcher.search(new MatchAllDocsQuery(), 1, new Sort(onefield.getSortField(true)));
FieldDoc first = (FieldDoc) results.scoreDocs[0];
assertEquals(45L, first.fields[0]);
}
public void testSimpleFieldEquivalences() throws Exception {
checkSorts(new MatchAllDocsQuery(), new Sort(new SortField("int", SortField.Type.INT, random().nextBoolean())));
checkSorts(new MatchAllDocsQuery(), new Sort(new SortField("long", SortField.Type.LONG, random().nextBoolean())));