From a9cf1503b59c24e8093459609dd56bb5339cda54 Mon Sep 17 00:00:00 2001 From: Joel Bernstein Date: Sat, 4 Feb 2017 23:48:03 -0500 Subject: [PATCH] SOLR-10094: /export handler (master only) loses the sort deep into the result set --- .../org/apache/solr/handler/ExportWriter.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/ExportWriter.java b/solr/core/src/java/org/apache/solr/handler/ExportWriter.java index e432f9473e5..8bdd959b52b 100644 --- a/solr/core/src/java/org/apache/solr/handler/ExportWriter.java +++ b/solr/core/src/java/org/apache/solr/handler/ExportWriter.java @@ -1254,7 +1254,6 @@ public class ExportWriter implements SolrCore.RawWriter, Closeable { class StringValue implements SortValue { protected SortedDocValues vals; - protected SortedDocValues segmentVals[]; protected MultiDocValues.OrdinalMap ordinalMap; protected LongValues globalOrds; @@ -1264,11 +1263,11 @@ public class ExportWriter implements SolrCore.RawWriter, Closeable { protected int segment; protected int currentOrd; protected IntComp comp; + protected int lastDocID; public StringValue(SortedDocValues vals, String field, IntComp comp) { this.vals = vals; if(vals instanceof MultiDocValues.MultiSortedDocValues) { - this.segmentVals = ((MultiDocValues.MultiSortedDocValues) vals).values; this.ordinalMap = ((MultiDocValues.MultiSortedDocValues) vals).mapping; } this.field = field; @@ -1281,6 +1280,13 @@ public class ExportWriter implements SolrCore.RawWriter, Closeable { } public void setCurrentValue(int docId) throws IOException { + + if (docId < lastDocID) { + throw new AssertionError("docs were sent out-of-order: lastDocID=" + lastDocID + " vs doc=" + docId); + } + + lastDocID = docId; + if (docId > currentVals.docID()) { currentVals.advance(docId); } @@ -1301,14 +1307,13 @@ public class ExportWriter implements SolrCore.RawWriter, Closeable { this.currentOrd = v.currentOrd; } - public void setNextReader(LeafReaderContext context) { + public void setNextReader(LeafReaderContext context) throws IOException { segment = context.ord; if(ordinalMap != null) { globalOrds = ordinalMap.getGlobalOrds(segment); - currentVals = segmentVals[segment]; - } else { - currentVals = vals; } + currentVals = DocValues.getSorted(context.reader(), field); + lastDocID = 0; } public void reset() {