Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-4779: factor out testEmptyIndex

Robert Muir873aca8ec93e
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<Integer> {
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);
+ }
}