diff --git a/solr/core/src/java/org/apache/solr/handler/export/StringValue.java b/solr/core/src/java/org/apache/solr/handler/export/StringValue.java index b7f020b3287..5df4eebf81b 100644 --- a/solr/core/src/java/org/apache/solr/handler/export/StringValue.java +++ b/solr/core/src/java/org/apache/solr/handler/export/StringValue.java @@ -96,10 +96,10 @@ class StringValue implements SortValue { } public void setNextReader(LeafReaderContext context) throws IOException { - if (globalDocValues instanceof MultiDocValues.MultiSortedDocValues) { + if (ordinalMap != null) { toGlobal = ordinalMap.getGlobalOrds(context.ord); - docValues = DocValues.getSorted(context.reader(), field); } + docValues = DocValues.getSorted(context.reader(), field); lastDocID = 0; } diff --git a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java index 6bb1bdbaecb..206132e54a9 100644 --- a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java +++ b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java @@ -84,6 +84,29 @@ public class TestExportWriter extends SolrTestCaseJ4 { } + @Test + public void testSortingOnFieldWithNoValues() throws Exception { + assertU(delQ("*:*")); + assertU(commit()); + + assertU(adoc("id","1")); + assertU(commit()); + + // 10 fields + List fieldNames = new ArrayList<>(Arrays.asList("floatdv", "intdv", "stringdv", "longdv", "doubledv", + "datedv", "booleandv", "field1_s_dv", "field2_i_p", "field3_l_p")); + for (String sortField : fieldNames) { + String resp = h.query(req("q", "*:*", "qt", "/export", "fl", "id," + sortField, "sort", sortField + " desc")); + assertJsonEquals(resp, "{\n" + + " \"responseHeader\":{\"status\":0},\n" + + " \"response\":{\n" + + " \"numFound\":1,\n" + + " \"docs\":[{\n" + + " \"id\":\"1\"}]}}"); + } + + } + public static void createIndex() { assertU(adoc("id","1", "floatdv","2.1",