Skip to content

Apache Lucene open-source search software

LUCENE-7400 - splitter should be able to group using sorted set dv

Tommaso Teofili53a34b312e78
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java
index 374624b41c6..8bb0b1dcdc2 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java
@@ -30,6 +30,7 @@ import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.ScoreDoc;
@@ -82,11 +83,20 @@ public class DatasetSplitter {
// get the exact no. of existing classes
int noOfClasses = 0;
for (LeafReaderContext leave : originalIndex.leaves()) {
+ long valueCount = 0;
SortedDocValues classValues = leave.reader().getSortedDocValues(classFieldName);
+ if (classValues != null) {
+ valueCount = classValues.getValueCount();
+ } else {
+ SortedSetDocValues sortedSetDocValues = leave.reader().getSortedSetDocValues(classFieldName);
+ if (sortedSetDocValues != null) {
+ valueCount = sortedSetDocValues.getValueCount();
+ }
+ }
if (classValues == null) {
- throw new IllegalStateException("the classFieldName \"" + classFieldName + "\" must index sorted doc values");
+ throw new IllegalStateException("field \"" + classFieldName + "\" must have sorted (set) doc values");
}
- noOfClasses += classValues.getValueCount();
+ noOfClasses += valueCount;
}
try {