diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java index 12ac42804a8..45b5fbbafd0 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java @@ -272,6 +272,11 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat { SimpleTextUtil.write(data, Integer.toString(valueCount), scratch); SimpleTextUtil.writeNewline(data); + // write fixedlength + SimpleTextUtil.write(data, FIXEDLENGTH); + SimpleTextUtil.write(data, Boolean.toString(fixedLength), scratch); + SimpleTextUtil.writeNewline(data); + // write maxLength SimpleTextUtil.write(data, MAXLENGTH); SimpleTextUtil.write(data, Integer.toString(maxLength), scratch); @@ -438,6 +443,9 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat { assert startsWith(NUMVALUES); field.numValues = Integer.parseInt(stripPrefix(NUMVALUES)); readLine(); + assert startsWith(FIXEDLENGTH); + field.fixedLength = Boolean.parseBoolean(stripPrefix(FIXEDLENGTH)); + readLine(); assert startsWith(MAXLENGTH); field.maxLength = Integer.parseInt(stripPrefix(MAXLENGTH)); readLine(); @@ -613,6 +621,21 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat { public int getValueCount() { return field.numValues; } + + @Override + public int size() { + return maxDoc; + } + + @Override + public boolean isFixedLength() { + return field.fixedLength; + } + + @Override + public int maxLength() { + return field.maxLength; + } }; } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/SortedDocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/SortedDocValuesConsumer.java index e8fd1616e3a..870d4907af7 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/SortedDocValuesConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/SortedDocValuesConsumer.java @@ -106,7 +106,7 @@ public abstract class SortedDocValuesConsumer { state.reader = reader; state.values = reader.getSortedDocValues(mergeState.fieldInfo.name); if (state.values == null) { - state.values = SortedDocValues.DEFAULT; + state.values = new SortedDocValues.EMPTY(maxDoc); } segStates.add(state); diff --git a/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java b/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java index e6c4c0ff54e..d6f30a7cdda 100644 --- a/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java +++ b/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java @@ -29,6 +29,8 @@ public abstract class BinaryDocValues { public abstract boolean isFixedLength(); public abstract int maxLength(); + // nocommit: rethink this api? alternative is boolean on atomicreader...? + // doc that the thing returned here must be thread safe... public BinaryDocValues newRAMInstance() { // TODO: optimize this default impl with e.g. isFixedLength/maxLength and so on // nocommit used packed ints/pagedbytes and so on @@ -66,6 +68,12 @@ public abstract class BinaryDocValues { public int maxLength() { return maxLength; } + + @Override + public BinaryDocValues newRAMInstance() { + // nocommit: ugly, maybe throw exception instead? + return this; + } }; } diff --git a/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java b/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java index 1359c4f3a92..831ed3794f0 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java +++ b/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java @@ -20,7 +20,7 @@ package org.apache.lucene.index; import org.apache.lucene.util.BytesRef; // nocommit need marker interface? -public abstract class SortedDocValues { +public abstract class SortedDocValues extends BinaryDocValues { // nocommit throws IOE or not? public abstract int getOrd(int docID); @@ -30,26 +30,110 @@ public abstract class SortedDocValues { // nocommit throws IOE or not? public abstract int getValueCount(); - // nocommit binary search lookup? - public static final SortedDocValues DEFAULT = new SortedDocValues() { - + @Override + public void get(int docID, BytesRef result) { + int ord = getOrd(docID); + lookupOrd(ord, result); + } + + @Override + public SortedDocValues newRAMInstance() { + // nocommit optimize this + // nocommit, see also BinaryDocValues nocommits + final int maxDoc = size(); + final int maxLength = maxLength(); + final boolean fixedLength = isFixedLength(); + final int valueCount = getValueCount(); + // nocommit used packed ints and so on + final byte[][] values = new byte[valueCount][]; + BytesRef scratch = new BytesRef(); + for(int ord=0;ord