Apache Solr open-source search software
make some progress fixing up lucene41 dv
Robert Muir52f62fe47082
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesConsumer.javaindex e6e6c2c0caa..37aaac5ae06 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesConsumer.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesConsumer.java@@ -25,6 +25,7 @@ import org.apache.lucene.codecs.SortedDocValuesConsumer;import org.apache.lucene.index.FieldInfo;import org.apache.lucene.index.IndexFileNames;import org.apache.lucene.index.SegmentInfo;+import org.apache.lucene.index.SegmentWriteState;import org.apache.lucene.store.CompoundFileDirectory;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;@@ -50,19 +51,27 @@ public class Lucene41DocValuesConsumer extends SimpleDVConsumer {private final Directory dir;private Directory cfs;private final IOContext context;+ private final String segmentSuffix;- Lucene41DocValuesConsumer(Directory dir, SegmentInfo si, IOContext context)- throws IOException {- this.dir = dir;- this.info = si;- this.context = context;+ Lucene41DocValuesConsumer(SegmentWriteState state) throws IOException {+ this.dir = state.directory;+ this.info = state.segmentInfo;+ this.context = state.context;+ this.segmentSuffix = state.segmentSuffix;}private synchronized Directory getDirectory() throws IOException {if (cfs == null) {- cfs = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(info.name, DV_SEGMENT_SUFFIX,- IndexFileNames.COMPOUND_FILE_EXTENSION), context, true);-+ final String suffix;+ if (segmentSuffix.length() == 0) {+ suffix = Lucene41DocValuesConsumer.DV_SEGMENT_SUFFIX;+ } else {+ suffix = segmentSuffix + "_" + Lucene41DocValuesConsumer.DV_SEGMENT_SUFFIX;+ }+ String fileName = IndexFileNames.segmentFileName(info.name,+ suffix,+ IndexFileNames.COMPOUND_FILE_EXTENSION);+ cfs = new CompoundFileDirectory(dir, fileName, context, true);}return cfs;}@@ -113,6 +122,7 @@ public class Lucene41DocValuesConsumer extends SimpleDVConsumer {}}+ // nocommit: bogus to put segmentName in here. think about copySegmentAsIs!!!!!!static String getDocValuesFileName(SegmentInfo info, FieldInfo field, String extension) {return IndexFileNames.segmentFileName(info.name + "_"+ field.number, DV_SEGMENT_SUFFIX, extension);diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesFormat.javaindex 21d8018b880..b909826691f 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesFormat.java@@ -34,13 +34,13 @@ public class Lucene41DocValuesFormat extends SimpleDocValuesFormat {@Overridepublic SimpleDVConsumer fieldsConsumer(SegmentWriteState state)throws IOException {- return new Lucene41DocValuesConsumer(state.directory, state.segmentInfo, state.context);+ return new Lucene41DocValuesConsumer(state);}@Overridepublic SimpleDVProducer fieldsProducer(SegmentReadState state)throws IOException {- return new Lucene41DocValuesProducer(state.directory, state.segmentInfo, state.fieldInfos, state.context);+ return new Lucene41DocValuesProducer(state);}}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesProducer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesProducer.javaindex a2e7788671f..96d8e1b6ce3 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesProducer.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/values/Lucene41DocValuesProducer.java@@ -18,22 +18,17 @@ package org.apache.lucene.codecs.lucene41.values;*/import java.io.Closeable;import java.io.IOException;-import java.util.ArrayList;-import java.util.HashMap;-import java.util.List;-import java.util.Map;import org.apache.lucene.codecs.SimpleDVProducer;import org.apache.lucene.index.BinaryDocValues;import org.apache.lucene.index.DocValues;import org.apache.lucene.index.FieldInfo;-import org.apache.lucene.index.FieldInfos;import org.apache.lucene.index.IndexFileNames;import org.apache.lucene.index.NumericDocValues;import org.apache.lucene.index.SegmentInfo;+import org.apache.lucene.index.SegmentReadState;import org.apache.lucene.index.SortedDocValues;import org.apache.lucene.store.CompoundFileDirectory;-import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.util.IOUtils;@@ -41,78 +36,61 @@ import org.apache.lucene.util.IOUtils;public class Lucene41DocValuesProducer extends SimpleDVProducer {private final CompoundFileDirectory cfs;+ // nocommit: remove thisprivate final SegmentInfo info;- private final Map<String,DocValuesFactory<NumericDocValues>> numeric = new HashMap<String,DocValuesFactory<NumericDocValues>>();- private final Map<String,DocValuesFactory<BinaryDocValues>> binary = new HashMap<String,DocValuesFactory<BinaryDocValues>>();- private final Map<String,DocValuesFactory<SortedDocValues>> sorted = new HashMap<String,DocValuesFactory<SortedDocValues>>();+ private final IOContext context;- public Lucene41DocValuesProducer(Directory dir, SegmentInfo segmentInfo,- FieldInfos fieldInfos, IOContext context) throws IOException {- this.cfs = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(- segmentInfo.name, Lucene41DocValuesConsumer.DV_SEGMENT_SUFFIX,- IndexFileNames.COMPOUND_FILE_EXTENSION), context, false);- this.info = segmentInfo;- for (FieldInfo fieldInfo : fieldInfos) {- if (fieldInfo.hasDocValues()) {- if (DocValues.isNumber(fieldInfo.getDocValuesType())- || DocValues.isFloat(fieldInfo.getDocValuesType())) {- numeric.put(fieldInfo.name, new Lucene41NumericDocValues.Factory(- this.cfs, this.info, fieldInfo, context));- } else if (DocValues.isBytes(fieldInfo.getDocValuesType())) {- binary.put(fieldInfo.name, new Lucene41BinaryDocValues.Factory(- this.cfs, this.info, fieldInfo, context));- } else {- assert DocValues.isSortedBytes(fieldInfo.getDocValuesType());- sorted.put(fieldInfo.name, new Lucene41SortedDocValues.Factory(- this.cfs, this.info, fieldInfo, context));- }- }+ public Lucene41DocValuesProducer(SegmentReadState state) throws IOException {+ final String suffix;+ if (state.segmentSuffix.length() == 0) {+ suffix = Lucene41DocValuesConsumer.DV_SEGMENT_SUFFIX;+ } else {+ suffix = state.segmentSuffix + "_" + Lucene41DocValuesConsumer.DV_SEGMENT_SUFFIX;}+ String cfsFileName = IndexFileNames.segmentFileName(state.segmentInfo.name, suffix,+ IndexFileNames.COMPOUND_FILE_EXTENSION);+ this.cfs = new CompoundFileDirectory(state.directory, cfsFileName, state.context, false);+ this.info = state.segmentInfo;+ this.context = state.context;}@Overridepublic void close() throws IOException {- try {- List<Closeable> closeables = new ArrayList<Closeable>(numeric.values());- closeables.addAll(binary.values());- closeables.addAll(sorted.values());- IOUtils.close(closeables);- } finally {- IOUtils.close(cfs);- }+ IOUtils.close(cfs);}@Overridepublic SimpleDVProducer clone() {- // nocommit todo- return null;+ return this; // nocommit ? actually safe since we open new each time from cfs?}@Overridepublic NumericDocValues getNumeric(FieldInfo field) throws IOException {- return valueOrNull(numeric, field);+ if (DocValues.isNumber(field.getDocValuesType()) || DocValues.isFloat(field.getDocValuesType())) {+ return new Lucene41NumericDocValues.Factory(this.cfs, this.info, field, context).getDirect();+ } else {+ return null;+ }}@Overridepublic BinaryDocValues getBinary(FieldInfo field) throws IOException {- return valueOrNull(binary, field);-+ if (DocValues.isBytes(field.getDocValuesType()) || DocValues.isSortedBytes(field.getDocValuesType())) {+ return new Lucene41BinaryDocValues.Factory(this.cfs, this.info, field, context).getDirect();+ } else {+ return null;+ }}@Overridepublic SortedDocValues getSorted(FieldInfo field) throws IOException {- return valueOrNull(sorted, field);- }-- private static <T> T valueOrNull(Map<String,DocValuesFactory<T>> map,- FieldInfo field) throws IOException {- final DocValuesFactory<T> docValuesFactory = map.get(field.name);- if (docValuesFactory != null) {- return docValuesFactory.getDirect();+ if (DocValues.isSortedBytes(field.getDocValuesType())) {+ return new Lucene41SortedDocValues.Factory(this.cfs, this.info, field, context).getDirect();+ } else {+ return null;}- return null;}-+public static abstract class DocValuesFactory<T> implements Closeable {public abstract T getDirect() throws IOException;