mirror of https://github.com/apache/lucene.git
LUCENE-4779: factor out testEmptyIndex
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1446257 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b17b827eca
commit
873aca8ec9
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue