Skip to content

Apache Lucene open-source search software

merged with trunk

Simon Willnauer9c2a60a0c077
diff --cc lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java
index 3f7faf62c20,c7f022e4747..cb4a0bfa8b4
--- a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java
+++ b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java
@@@ -26,12 -27,7 +27,11 @@@ import java.util.Map
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.DocumentsWriterPerThread.DocState;
+import org.apache.lucene.index.codecs.Codec;
+import org.apache.lucene.index.codecs.PerDocConsumer;
+import org.apache.lucene.index.codecs.docvalues.DocValuesConsumer;
- import org.apache.lucene.index.values.PerDocFieldValues;
- import org.apache.lucene.store.Directory;
+ import org.apache.lucene.util.ArrayUtil;
/**
@@@ -282,88 -260,4 +288,28 @@@ final class DocFieldProcessor extends D
}
}
- void quickSort(DocFieldProcessorPerField[] array, int lo, int hi) {
- if (lo >= hi)
- return;
- else if (hi == 1+lo) {
- if (array[lo].fieldInfo.name.compareTo(array[hi].fieldInfo.name) > 0) {
- final DocFieldProcessorPerField tmp = array[lo];
- array[lo] = array[hi];
- array[hi] = tmp;
- }
- return;
- }
-
- int mid = (lo + hi) >>> 1;
-
- if (array[lo].fieldInfo.name.compareTo(array[mid].fieldInfo.name) > 0) {
- DocFieldProcessorPerField tmp = array[lo];
- array[lo] = array[mid];
- array[mid] = tmp;
- }
-
- if (array[mid].fieldInfo.name.compareTo(array[hi].fieldInfo.name) > 0) {
- DocFieldProcessorPerField tmp = array[mid];
- array[mid] = array[hi];
- array[hi] = tmp;
-
- if (array[lo].fieldInfo.name.compareTo(array[mid].fieldInfo.name) > 0) {
- DocFieldProcessorPerField tmp2 = array[lo];
- array[lo] = array[mid];
- array[mid] = tmp2;
- }
- }
-
- int left = lo + 1;
- int right = hi - 1;
-
- if (left >= right)
- return;
-
- DocFieldProcessorPerField partition = array[mid];
-
- for (; ;) {
- while (array[right].fieldInfo.name.compareTo(partition.fieldInfo.name) > 0)
- --right;
-
- while (left < right && array[left].fieldInfo.name.compareTo(partition.fieldInfo.name) <= 0)
- ++left;
-
- if (left < right) {
- DocFieldProcessorPerField tmp = array[left];
- array[left] = array[right];
- array[right] = tmp;
- --right;
- } else {
- break;
- }
- }
-
- quickSort(array, lo, left);
- quickSort(array, left + 1, hi);
- }
+ final private Map<String, DocValuesConsumer> docValues = new HashMap<String, DocValuesConsumer>();
+ final private Map<Integer, PerDocConsumer> perDocConsumers = new HashMap<Integer, PerDocConsumer>();
+
+ DocValuesConsumer docValuesConsumer(DocState docState, FieldInfo fieldInfo, FieldInfos infos)
+ throws IOException {
+ DocValuesConsumer docValuesConsumer = docValues.get(fieldInfo.name);
+ if (docValuesConsumer != null) {
+ return docValuesConsumer;
+ }
+ PerDocConsumer perDocConsumer = perDocConsumers.get(fieldInfo.getCodecId());
+ if (perDocConsumer == null) {
+ PerDocWriteState perDocWriteState = docState.docWriter.newPerDocWriteState(fieldInfo.getCodecId());
+ SegmentCodecs codecs = perDocWriteState.segmentCodecs;
+ assert codecs.codecs.length > fieldInfo.getCodecId();
+
+ Codec codec = codecs.codecs[fieldInfo.getCodecId()];
+ perDocConsumer = codec.docsConsumer(perDocWriteState);
+ perDocConsumers.put(Integer.valueOf(fieldInfo.getCodecId()), perDocConsumer);
+ }
+ docValuesConsumer = perDocConsumer.addValuesField(fieldInfo);
+ docValues.put(fieldInfo.name, docValuesConsumer);
+ return docValuesConsumer;
+ }
+
}