diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java b/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java index 38609630587..13a5168c924 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDoubleValuesSource.java @@ -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()))); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java b/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java index 9148ad5b544..8b20be5169d 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestLongValuesSource.java @@ -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())));