From 873aca8ec93e83c15ada6c5156036a29abee11b3 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 14 Feb 2013 16:13:05 +0000 Subject: [PATCH] LUCENE-4779: factor out testEmptyIndex git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1446257 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/search/TestSort.java | 41 ------------------- .../org/apache/lucene/search/TestSort2.java | 31 ++++++++++++++ 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java index 7909cc89899..5ad87e889ad 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java @@ -351,11 +351,6 @@ public class TestSort extends LuceneTestCase { return getIndex(false, true); } - private IndexSearcher getEmptyIndex() - throws IOException { - return getIndex(false, false); - } - // Set to true if the DV "string" field is indexed as a // sorted source: private boolean dvStringSorted; @@ -710,42 +705,6 @@ public class TestSort extends LuceneTestCase { fc.purgeAllCaches(); } - // test sorts when there's nothing in the index - public void testEmptyIndex() throws Exception { - IndexSearcher empty = getEmptyIndex(); - - sort = new Sort(); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(SortField.FIELD_DOC); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("int", SortField.Type.INT), SortField.FIELD_DOC); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("int_dv", SortField.Type.INT), SortField.FIELD_DOC); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("string", SortField.Type.STRING, true), SortField.FIELD_DOC); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("float", SortField.Type.FLOAT), new SortField("string", SortField.Type.STRING)); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("float_dv", SortField.Type.FLOAT), new SortField("string", SortField.Type.STRING)); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("string_dv", getDVStringSortType(false), true), SortField.FIELD_DOC); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("float_dv", SortField.Type.FLOAT), - new SortField("string_dv", getDVStringSortType(false))); - assertMatches(empty, queryX, sort, ""); - - sort.setSort(new SortField("float_dv", SortField.Type.FLOAT), new SortField("string_dv", getDVStringSortType(false))); - assertMatches(empty, queryX, sort, ""); - } - static class MyFieldComparator extends FieldComparator { FieldCache.Ints docValues; int[] slotValues; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort2.java b/lucene/core/src/test/org/apache/lucene/search/TestSort2.java index cec72e02788..f08b6ebcd11 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSort2.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSort2.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.MultiReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; @@ -157,4 +158,34 @@ public class TestSort2 extends LuceneTestCase { r.close(); d.close(); } + + // test sorts when there's nothing in the index + public void testEmptyIndex() throws Exception { + IndexSearcher empty = new IndexSearcher(new MultiReader()); + Query query = new TermQuery(new Term("contents", "foo")); + + Sort sort = new Sort(); + TopDocs td = empty.search(query, null, 10, sort, true, true); + assertEquals(0, td.totalHits); + + sort.setSort(SortField.FIELD_DOC); + td = empty.search(query, null, 10, sort, true, true); + assertEquals(0, td.totalHits); + + sort.setSort(new SortField("int", SortField.Type.INT), SortField.FIELD_DOC); + td = empty.search(query, null, 10, sort, true, true); + assertEquals(0, td.totalHits); + + sort.setSort(new SortField("string", SortField.Type.STRING, true), SortField.FIELD_DOC); + td = empty.search(query, null, 10, sort, true, true); + assertEquals(0, td.totalHits); + + sort.setSort(new SortField("string_val", SortField.Type.STRING_VAL, true), SortField.FIELD_DOC); + td = empty.search(query, null, 10, sort, true, true); + assertEquals(0, td.totalHits); + + sort.setSort(new SortField("float", SortField.Type.FLOAT), new SortField("string", SortField.Type.STRING)); + td = empty.search(query, null, 10, sort, true, true); + assertEquals(0, td.totalHits); + } }