Skip to content

Apache Lucene open-source search software

merged with trunk

Simon Willnauerc51bbaeda012
diff --cc lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java
index ac4d8a210d7,6324f628423..eb13e033a1f
--- a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java
+++ b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java
@@@ -100,18 -100,28 +107,36 @@@ final class DocFieldProcessor extends D
}
}
+ for(PerDocConsumer consumer : perDocConsumers.values()) {
+ try {
+ consumer.close(); // TODO add abort to PerDocConsumer!
+ } catch (IOException e) {
+ // ignore on abort!
+ }
+ }
-
++
try {
fieldsWriter.abort();
- } finally {
+ } catch (Throwable t) {
+ if (th == null) {
+ th = t;
+ }
+ }
+
+ try {
consumer.abort();
+ } catch (Throwable t) {
+ if (th == null) {
+ th = t;
+ }
+ }
+
+ // If any errors occured, throw it.
+ if (th != null) {
+ if (th instanceof RuntimeException) throw (RuntimeException) th;
+ if (th instanceof Error) throw (Error) th;
+ // defensive code - we should not hit unchecked exceptions
+ throw new RuntimeException(th);
}
}
diff --cc lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java
index fd4e6f3e795,7e3d45edede..10aa7c24d97
--- a/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java
+++ b/lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java
@@@ -30,12 -28,9 +30,13 @@@ import java.util.TreeSet
import org.apache.lucene.index.codecs.Codec;
import org.apache.lucene.index.codecs.FieldsConsumer;
import org.apache.lucene.index.codecs.FieldsProducer;
+import org.apache.lucene.index.codecs.PerDocConsumer;
+import org.apache.lucene.index.codecs.PerDocValues;
import org.apache.lucene.index.codecs.TermsConsumer;
+import org.apache.lucene.index.codecs.DocValuesConsumer;
+import org.apache.lucene.index.values.DocValues;
import org.apache.lucene.store.Directory;
+ import org.apache.lucene.util.IOUtils;
/**
* Enables native per field codec support. This class selects the codec used to
@@@ -67,7 -62,15 +68,15 @@@ final class PerFieldCodecWrapper extend
assert segmentCodecs == state.segmentCodecs;
final Codec[] codecs = segmentCodecs.codecs;
for (int i = 0; i < codecs.length; i++) {
- consumers.add(codecs[i].fieldsConsumer(new SegmentWriteState(state, i)));
+ boolean success = false;
+ try {
- consumers.add(codecs[i].fieldsConsumer(new SegmentWriteState(state, "" + i)));
++ consumers.add(codecs[i].fieldsConsumer(new SegmentWriteState(state, i)));
+ success = true;
+ } finally {
+ if (!success) {
+ IOUtils.closeSafely(true, consumers);
+ }
+ }
}
}
@@@ -181,25 -161,10 +168,10 @@@
FieldsProducer fields = codecs.get(field);
return fields == null ? null : fields.terms(field);
}
-
+
@Override
public void close() throws IOException {
- Iterator<FieldsProducer> it = codecs.values().iterator();
- IOException err = null;
- while (it.hasNext()) {
- try {
- it.next().close();
- } catch (IOException ioe) {
- // keep first IOException we hit but keep
- // closing the rest
- if (err == null) {
- err = ioe;
- }
- }
- }
- if (err != null) {
- throw err;
- }
+ IOUtils.closeSafely(false, codecs.values());
}
@Override
diff --cc lucene/src/java/org/apache/lucene/index/SegmentMerger.java
index c2f25fb006e,8a647e3a077..3c098de8635
--- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java
+++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java
@@@ -27,11 -27,8 +27,10 @@@ import org.apache.lucene.document.Docum
import org.apache.lucene.index.IndexReader.FieldOption;
import org.apache.lucene.index.MergePolicy.MergeAbortedException;
import org.apache.lucene.index.codecs.Codec;
- import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.index.codecs.FieldsConsumer;
import org.apache.lucene.index.codecs.MergeState;
+import org.apache.lucene.index.codecs.PerDocConsumer;
+import org.apache.lucene.index.codecs.PerDocValues;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
diff --cc lucene/src/java/org/apache/lucene/index/codecs/BlockTermsWriter.java
index e24c2c45841,9cb9d4cbd8d..b7a82ec0d66
--- a/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsWriter.java
@@@ -66,24 -67,29 +67,29 @@@ public class BlockTermsWriter extends F
//private final String segment;
- public BlockTermsWriter(
- TermsIndexWriterBase termsIndexWriter,
- SegmentWriteState state,
- PostingsWriterBase postingsWriter)
- throws IOException
- {
+ public BlockTermsWriter(TermsIndexWriterBase termsIndexWriter,
+ SegmentWriteState state, PostingsWriterBase postingsWriter)
+ throws IOException {
- final String termsFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, TERMS_EXTENSION);
+ final String termsFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), TERMS_EXTENSION);
this.termsIndexWriter = termsIndexWriter;
out = state.directory.createOutput(termsFileName);
- fieldInfos = state.fieldInfos;
- writeHeader(out);
- currentField = null;
- this.postingsWriter = postingsWriter;
- //segment = state.segmentName;
-
- //System.out.println("BTW.init seg=" + state.segmentName);
-
- postingsWriter.start(out); // have consumer write its format/header
+ boolean success = false;
+ try {
+ fieldInfos = state.fieldInfos;
+ writeHeader(out);
+ currentField = null;
+ this.postingsWriter = postingsWriter;
+ //segment = state.segmentName;
+
+ //System.out.println("BTW.init seg=" + state.segmentName);
+
+ postingsWriter.start(out); // have consumer write its format/header
+ success = true;
+ } finally {
+ if (!success) {
+ IOUtils.closeSafely(true, out);
+ }
+ }
}
protected void writeHeader(IndexOutput out) throws IOException {
diff --cc lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexWriter.java
index 355665609c3,38f094d47c0..a2ef5f28765
--- a/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexWriter.java
@@@ -55,12 -56,20 +56,20 @@@ public class FixedGapTermsIndexWriter e
private final FieldInfos fieldInfos; // unread
public FixedGapTermsIndexWriter(SegmentWriteState state) throws IOException {
- final String indexFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, TERMS_INDEX_EXTENSION);
+ final String indexFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), TERMS_INDEX_EXTENSION);
termIndexInterval = state.termIndexInterval;
out = state.directory.createOutput(indexFileName);
- fieldInfos = state.fieldInfos;
- writeHeader(out);
- out.writeInt(termIndexInterval);
+ boolean success = false;
+ try {
+ fieldInfos = state.fieldInfos;
+ writeHeader(out);
+ out.writeInt(termIndexInterval);
+ success = true;
+ } finally {
+ if (!success) {
+ IOUtils.closeSafely(true, out);
+ }
+ }
}
protected void writeHeader(IndexOutput out) throws IOException {
diff --cc lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexWriter.java
index 21aa6316e3d,d10608879cb..3305188506b
--- a/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexWriter.java
@@@ -157,11 -158,19 +158,19 @@@ public class VariableGapTermsIndexWrite
// in the extremes.
public VariableGapTermsIndexWriter(SegmentWriteState state, IndexTermSelector policy) throws IOException {
- final String indexFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, TERMS_INDEX_EXTENSION);
+ final String indexFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), TERMS_INDEX_EXTENSION);
out = state.directory.createOutput(indexFileName);
- fieldInfos = state.fieldInfos;
- this.policy = policy;
- writeHeader(out);
+ boolean success = false;
+ try {
+ fieldInfos = state.fieldInfos;
+ this.policy = policy;
+ writeHeader(out);
+ success = true;
+ } finally {
+ if (!success) {
+ IOUtils.closeSafely(true, out);
+ }
+ }
}
protected void writeHeader(IndexOutput out) throws IOException {
diff --cc lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java
index 2ecae8a3bb2,c79545dbfd4..987d9d51d57
--- a/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingCodec.java
@@@ -29,13 -28,8 +29,12 @@@ import org.apache.lucene.index.codecs.P
import org.apache.lucene.index.codecs.standard.StandardPostingsWriter;
import org.apache.lucene.index.codecs.PostingsReaderBase;
import org.apache.lucene.index.codecs.standard.StandardPostingsReader;
- import org.apache.lucene.index.codecs.DocValuesConsumer;
+import org.apache.lucene.index.codecs.DefaultDocValuesProducer;
import org.apache.lucene.index.codecs.FieldsConsumer;
import org.apache.lucene.index.codecs.FieldsProducer;
+import org.apache.lucene.index.codecs.PerDocConsumer;
+import org.apache.lucene.index.codecs.DefaultDocValuesConsumer;
+import org.apache.lucene.index.codecs.PerDocValues;
import org.apache.lucene.index.codecs.VariableGapTermsIndexReader;
import org.apache.lucene.index.codecs.VariableGapTermsIndexWriter;
import org.apache.lucene.index.codecs.BlockTermsReader;
@@@ -44,7 -38,7 +43,8 @@@ import org.apache.lucene.index.codecs.T
import org.apache.lucene.index.codecs.TermsIndexWriterBase;
import org.apache.lucene.index.codecs.standard.StandardCodec;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.BytesRef;
+ import org.apache.lucene.util.IOUtils;
/** This codec "inlines" the postings for terms that have
* low docFreq. It wraps another codec, which is used for
diff --cc lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java
index f14658cba45,e4c5a484865..7a7219a7fee
--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriterImpl.java
@@@ -107,45 -108,51 +108,51 @@@ public final class SepPostingsWriterImp
}
public SepPostingsWriterImpl(SegmentWriteState state, IntStreamFactory factory, int skipInterval) throws IOException {
- super();
- final String codecIdAsString = state.codecIdAsString();
- this.skipInterval = skipInterval;
- this.skipMinimum = skipInterval; /* set to the same for now */
- final String docFileName = IndexFileNames.segmentFileName(state.segmentName, codecIdAsString, DOC_EXTENSION);
- docOut = factory.createOutput(state.directory, docFileName);
- docIndex = docOut.index();
-
- if (state.fieldInfos.hasProx()) {
- final String frqFileName = IndexFileNames.segmentFileName(state.segmentName, codecIdAsString, FREQ_EXTENSION);
- freqOut = factory.createOutput(state.directory, frqFileName);
- freqIndex = freqOut.index();
-
- final String posFileName = IndexFileNames.segmentFileName(state.segmentName, codecIdAsString, POS_EXTENSION);
- posOut = factory.createOutput(state.directory, posFileName);
- posIndex = posOut.index();
-
- // TODO: -- only if at least one field stores payloads?
- final String payloadFileName = IndexFileNames.segmentFileName(state.segmentName, codecIdAsString, PAYLOAD_EXTENSION);
- payloadOut = state.directory.createOutput(payloadFileName);
+ freqOut = null;
+ freqIndex = null;
+ posOut = null;
+ posIndex = null;
+ payloadOut = null;
+ boolean success = false;
+ try {
+ this.skipInterval = skipInterval;
+ this.skipMinimum = skipInterval; /* set to the same for now */
- final String docFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, DOC_EXTENSION);
++ final String docFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), DOC_EXTENSION);
+ docOut = factory.createOutput(state.directory, docFileName);
+ docIndex = docOut.index();
+
+ if (state.fieldInfos.hasProx()) {
- final String frqFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, FREQ_EXTENSION);
++ final String frqFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), FREQ_EXTENSION);
+ freqOut = factory.createOutput(state.directory, frqFileName);
+ freqIndex = freqOut.index();
+
- final String posFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, POS_EXTENSION);
++ final String posFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), POS_EXTENSION);
+ posOut = factory.createOutput(state.directory, posFileName);
+ posIndex = posOut.index();
+
+ // TODO: -- only if at least one field stores payloads?
- final String payloadFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, PAYLOAD_EXTENSION);
++ final String payloadFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), PAYLOAD_EXTENSION);
+ payloadOut = state.directory.createOutput(payloadFileName);
+ }
+
- final String skipFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, SKIP_EXTENSION);
++ final String skipFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), SKIP_EXTENSION);
+ skipOut = state.directory.createOutput(skipFileName);
+
+ totalNumDocs = state.numDocs;
+
+ skipListWriter = new SepSkipListWriter(skipInterval,
+ maxSkipLevels,
+ state.numDocs,
+ freqOut, docOut,
+ posOut, payloadOut);
+
+ success = true;
+ } finally {
+ if (!success) {
+ IOUtils.closeSafely(true, docOut, skipOut, freqOut, posOut, payloadOut);
+ }
- } else {
- freqOut = null;
- freqIndex = null;
- posOut = null;
- posIndex = null;
- payloadOut = null;
}
-
- final String skipFileName = IndexFileNames.segmentFileName(state.segmentName, codecIdAsString, SKIP_EXTENSION);
- skipOut = state.directory.createOutput(skipFileName);
-
- totalNumDocs = state.numDocs;
-
- skipListWriter = new SepSkipListWriter(skipInterval,
- maxSkipLevels,
- state.numDocs,
- freqOut, docOut,
- posOut, payloadOut);
}
@Override
diff --cc lucene/src/java/org/apache/lucene/index/codecs/standard/StandardPostingsWriter.java
index a0d1a8d076e,457e3c24821..1b7021b2bf5
--- a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardPostingsWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardPostingsWriter.java
@@@ -89,27 -91,30 +91,30 @@@ public final class StandardPostingsWrit
this.skipInterval = skipInterval;
this.skipMinimum = skipInterval; /* set to the same for now */
//this.segment = state.segmentName;
- String fileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, StandardCodec.FREQ_EXTENSION);
+ String fileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), StandardCodec.FREQ_EXTENSION);
freqOut = state.directory.createOutput(fileName);
-
- if (state.fieldInfos.hasProx()) {
- // At least one field does not omit TF, so create the
- // prox file
- fileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), StandardCodec.PROX_EXTENSION);
- proxOut = state.directory.createOutput(fileName);
- } else {
- // Every field omits TF so we will write no prox file
- proxOut = null;
+ boolean success = false;
+ try {
+ if (state.fieldInfos.hasProx()) {
+ // At least one field does not omit TF, so create the
+ // prox file
- fileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, StandardCodec.PROX_EXTENSION);
++ fileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), StandardCodec.PROX_EXTENSION);
+ proxOut = state.directory.createOutput(fileName);
+ } else {
+ // Every field omits TF so we will write no prox file
+ proxOut = null;
+ }
+
+ totalNumDocs = state.numDocs;
+
+ skipListWriter = new DefaultSkipListWriter(skipInterval, maxSkipLevels,
+ state.numDocs, freqOut, proxOut);
+ success = true;
+ } finally {
+ if (!success) {
+ IOUtils.closeSafely(true, freqOut, proxOut);
+ }
}
-
- totalNumDocs = state.numDocs;
-
- skipListWriter = new DefaultSkipListWriter(skipInterval,
- maxSkipLevels,
- state.numDocs,
- freqOut,
- proxOut);
}
@Override
diff --cc lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java
index d2a2d9fd355,627690bea43..4f6d5759a46
--- a/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java
+++ b/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java
@@@ -120,58 -98,45 +121,94 @@@ public class RandomIndexWriter implemen
* Adds a Document.
* @see IndexWriter#addDocument(Document)
*/
- public void addDocument(Document doc) throws IOException {
+ public void addDocument(final Document doc) throws IOException {
+ if (doDocValues) {
+ randomPerDocFieldValues(r, doc);
+ }
- w.addDocument(doc);
++
+ if (r.nextInt(5) == 3) {
+ // TODO: maybe, we should simply buffer up added docs
+ // (but we need to clone them), and only when
+ // getReader, commit, etc. are called, we do an
+ // addDocuments? Would be better testing.
+ w.addDocuments(new Iterable<Document>() {
+
+ // @Override -- not until Java 1.6
+ public Iterator<Document> iterator() {
+ return new Iterator<Document>() {
+ boolean done;
+
+ // @Override -- not until Java 1.6
+ public boolean hasNext() {
+ return !done;
+ }
+
+ // @Override -- not until Java 1.6
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ // @Override -- not until Java 1.6
+ public Document next() {
+ if (done) {
+ throw new IllegalStateException();
+ }
+ done = true;
+ return doc;
+ }
+ };
+ }
+ });
+ } else {
+ w.addDocument(doc);
+ }
+
maybeCommit();
}
+
+ private void randomPerDocFieldValues(Random random, Document doc) {
+
+ ValueType[] values = ValueType.values();
+ ValueType type = values[random.nextInt(values.length)];
+ String name = "random_" + type.name() + "" + docValuesFieldPrefix;
+ if ("PreFlex".equals(codecProvider.getFieldCodec(name)) || doc.getFieldable(name) != null)
+ return;
+ DocValuesField docValuesField = new DocValuesField(name);
+ switch (type) {
+ case BYTES_FIXED_DEREF:
+ case BYTES_FIXED_SORTED:
+ case BYTES_FIXED_STRAIGHT:
+ final String randomUnicodeString = _TestUtil.randomUnicodeString(random, fixedBytesLength);
+ BytesRef fixedRef = new BytesRef(randomUnicodeString);
+ if (fixedRef.length > fixedBytesLength) {
+ fixedRef = new BytesRef(fixedRef.bytes, 0, fixedBytesLength);
+ } else {
+ fixedRef.grow(fixedBytesLength);
+ fixedRef.length = fixedBytesLength;
+ }
+ docValuesField.setBytes(fixedRef, type);
+ break;
+ case BYTES_VAR_DEREF:
+ case BYTES_VAR_SORTED:
+ case BYTES_VAR_STRAIGHT:
+ BytesRef ref = new BytesRef(_TestUtil.randomUnicodeString(random, 200));
+ docValuesField.setBytes(ref, type);
+ break;
+ case FLOAT_32:
+ docValuesField.setFloat(random.nextFloat());
+ break;
+ case FLOAT_64:
+ docValuesField.setFloat(random.nextDouble());
+ break;
+ case INTS:
+ docValuesField.setInt(random.nextInt());
+ break;
+ default:
+ throw new IllegalArgumentException("no such type: " + type);
+ }
+
+ doc.add(docValuesField);
+ }
private void maybeCommit() throws IOException {
if (docCount++ == flushAt) {
@@@ -192,11 -166,39 +239,43 @@@
* Updates a document.
* @see IndexWriter#updateDocument(Term, Document)
*/
- public void updateDocument(Term t, Document doc) throws IOException {
- public void updateDocument(Term t, final Document doc) throws IOException {
++ public void updateDocument(final Term t, final Document doc) throws IOException {
+ if (doDocValues) {
+ randomPerDocFieldValues(r, doc);
+ }
- w.updateDocument(t, doc);
++
+ if (r.nextInt(5) == 3) {
+ w.updateDocuments(t, new Iterable<Document>() {
+
+ // @Override -- not until Java 1.6
+ public Iterator<Document> iterator() {
+ return new Iterator<Document>() {
+ boolean done;
+
+ // @Override -- not until Java 1.6
+ public boolean hasNext() {
+ return !done;
+ }
+
+ // @Override -- not until Java 1.6
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ // @Override -- not until Java 1.6
+ public Document next() {
+ if (done) {
+ throw new IllegalStateException();
+ }
+ done = true;
+ return doc;
+ }
+ };
+ }
+ });
+ } else {
+ w.updateDocument(t, doc);
+ }
maybeCommit();
}
diff --cc lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java
index 902bbb14bac,1a611471d4d..90e4be7ba68
--- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java
+++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java
@@@ -140,10 -134,13 +140,13 @@@ public class MockRandomCodec extends Co
System.out.println("MockRandomCodec: writing to seg=" + state.segmentName + " seed=" + seed);
}
- final String seedFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecId, SEED_EXT);
+ final String seedFileName = IndexFileNames.segmentFileName(state.segmentName, state.codecIdAsString(), SEED_EXT);
final IndexOutput out = state.directory.createOutput(seedFileName);
- out.writeLong(seed);
- out.close();
+ try {
+ out.writeLong(seed);
+ } finally {
+ out.close();
+ }
final Random random = new Random(seed);
diff --cc lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
index a2003215737,020f08b9f7d..92da41f6fc7
--- a/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
+++ b/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
@@@ -401,7 -370,54 +401,54 @@@ public class _TestUtil
List<Fieldable> fields = doc.getFields();
for (Fieldable field : fields) {
fieldInfos.addOrUpdate(field.name(), field.isIndexed(), field.isTermVectorStored(), field.isStorePositionWithTermVector(),
- field.isStoreOffsetWithTermVector(), field.getOmitNorms(), false, field.getOmitTermFreqAndPositions());
+ field.isStoreOffsetWithTermVector(), field.getOmitNorms(), false, field.getOmitTermFreqAndPositions(), field.docValuesType());
}
}
+
+ /**
+ * insecure, fast version of File.createTempFile
+ * uses Random instead of SecureRandom.
+ */
+ public static File createTempFile(String prefix, String suffix, File directory)
+ throws IOException {
+ // Force a prefix null check first
+ if (prefix.length() < 3) {
+ throw new IllegalArgumentException("prefix must be 3");
+ }
+ String newSuffix = suffix == null ? ".tmp" : suffix;
+ File result;
+ do {
+ result = genTempFile(prefix, newSuffix, directory);
+ } while (!result.createNewFile());
+ return result;
+ }
+
+ /* Temp file counter */
+ private static int counter = 0;
+
+ /* identify for differnt VM processes */
+ private static int counterBase = 0;
+
+ private static class TempFileLocker {};
+ private static TempFileLocker tempFileLocker = new TempFileLocker();
+
+ private static File genTempFile(String prefix, String suffix, File directory) {
+ int identify = 0;
+
+ synchronized (tempFileLocker) {
+ if (counter == 0) {
+ int newInt = new Random().nextInt();
+ counter = ((newInt / 65535) & 0xFFFF) + 0x2710;
+ counterBase = counter;
+ }
+ identify = counter++;
+ }
+
+ StringBuilder newName = new StringBuilder();
+ newName.append(prefix);
+ newName.append(counterBase);
+ newName.append(identify);
+ newName.append(suffix);
+ return new File(directory, newName.toString());
+ }
}