From 1a740cad063db6886f34f068efea3c15de284e16 Mon Sep 17 00:00:00 2001
From: Shai Erera
Date: Sat, 28 Sep 2013 06:19:00 +0000
Subject: [PATCH] LUCENE-5215: Add support for FieldInfos generation
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1527154 13f79535-47bb-0310-9956-ffa450edef68
---
.../SimpleTextFieldInfosReader.java | 9 +-
.../SimpleTextFieldInfosWriter.java | 9 +-
.../java/org/apache/lucene/codecs/Codec.java | 2 +-
.../lucene/codecs/FieldInfosReader.java | 2 +-
.../lucene/codecs/FieldInfosWriter.java | 2 +-
.../org/apache/lucene/codecs/FilterCodec.java | 4 +-
.../lucene40/Lucene40FieldInfosReader.java | 2 +-
.../lucene/codecs/lucene42/Lucene42Codec.java | 2 +-
.../lucene42/Lucene42FieldInfosFormat.java | 7 +-
.../lucene42/Lucene42FieldInfosReader.java | 4 +-
.../lucene/codecs/lucene45/Lucene45Codec.java | 4 +-
.../lucene/codecs/lucene46/Lucene46Codec.java | 139 ++++++
.../lucene46/Lucene46FieldInfosFormat.java | 126 ++++++
.../lucene46/Lucene46FieldInfosReader.java | 125 ++++++
.../lucene46/Lucene46FieldInfosWriter.java | 109 +++++
.../lucene/codecs/lucene46/package.html | 398 ++++++++++++++++++
.../org/apache/lucene/codecs/package.html | 6 +-
.../perfield/PerFieldDocValuesFormat.java | 33 +-
.../lucene/index/DocFieldProcessor.java | 2 +-
.../org/apache/lucene/index/FieldInfo.java | 20 +-
.../org/apache/lucene/index/IndexWriter.java | 44 +-
.../lucene/index/ReadersAndLiveDocs.java | 46 +-
.../lucene/index/SegmentCoreReaders.java | 20 +-
.../lucene/index/SegmentInfoPerCommit.java | 88 ++--
.../org/apache/lucene/index/SegmentInfos.java | 43 +-
.../apache/lucene/index/SegmentMerger.java | 2 +-
.../apache/lucene/index/SegmentReader.java | 70 ++-
.../lucene/index/SegmentWriteState.java | 12 +-
.../lucene/index/StandardDirectoryReader.java | 2 +-
.../services/org.apache.lucene.codecs.Codec | 3 +-
.../org/apache/lucene/TestExternalCodecs.java | 4 +-
.../perfield/TestPerFieldDocValuesFormat.java | 4 +-
.../perfield/TestPerFieldPostingsFormat2.java | 12 +-
.../apache/lucene/index/TestAddIndexes.java | 7 +-
.../index/TestAllFilesHaveCodecHeader.java | 7 +-
.../index/TestBackwardsCompatibility.java | 9 +-
.../index/TestConsistentFieldNumbers.java | 27 +-
.../lucene/index/TestDuelingCodecs.java | 2 +-
.../apache/lucene/index/TestFieldInfos.java | 13 +-
.../index/TestNumericDocValuesUpdates.java | 117 ++++-
.../lucene/index/TestTermVectorsReader.java | 2 +-
.../lucene/util/TestNamedSPILoader.java | 9 +-
.../Facet46Codec.java} | 12 +-
.../codecs/{facet45 => facet46}/package.html | 0
.../apache/lucene/facet/FacetTestCase.java | 4 +-
.../lucene/facet/search/TestDemoFacets.java | 4 +-
.../apache/lucene/index/IndexSplitter.java | 2 +-
.../analyzing/AnalyzingInfixSuggester.java | 4 +-
.../codecs/asserting/AssertingCodec.java | 6 +-
.../cheapbastard/CheapBastardCodec.java | 5 +-
.../codecs/compressing/CompressingCodec.java | 6 +-
.../lucene40/Lucene40FieldInfosWriter.java | 3 +-
.../lucene42/Lucene42FieldInfosWriter.java | 5 +-
.../codecs/lucene42/Lucene42RWCodec.java | 21 +
.../codecs/lucene45/Lucene45RWCodec.java | 48 +++
.../lucene/codecs/lucene45/package.html | 25 ++
.../index/BasePostingsFormatTestCase.java | 4 +-
.../index/BaseStoredFieldsFormatTestCase.java | 12 +-
.../org/apache/lucene/index/RandomCodec.java | 20 +-
.../apache/lucene/util/LuceneTestCase.java | 2 +-
.../util/TestRuleSetupAndRestoreClassEnv.java | 26 +-
.../org/apache/lucene/util/_TestUtil.java | 35 +-
.../services/org.apache.lucene.codecs.Codec | 1 +
.../apache/solr/core/SchemaCodecFactory.java | 4 +-
64 files changed, 1425 insertions(+), 372 deletions(-)
create mode 100755 lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java
create mode 100755 lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java
create mode 100755 lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java
create mode 100755 lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java
create mode 100755 lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html
rename lucene/facet/src/java/org/apache/lucene/facet/codecs/{facet45/Facet45Codec.java => facet46/Facet46Codec.java} (89%)
mode change 100644 => 100755
rename lucene/facet/src/java/org/apache/lucene/facet/codecs/{facet45 => facet46}/package.html (100%)
mode change 100644 => 100755
rename lucene/{core => test-framework}/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosWriter.java (94%)
create mode 100644 lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java
create mode 100644 lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/package.html
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java
index d7f91107f29..caa8d39fe74 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java
@@ -47,8 +47,8 @@ import static org.apache.lucene.codecs.simpletext.SimpleTextFieldInfosWriter.*;
public class SimpleTextFieldInfosReader extends FieldInfosReader {
@Override
- public FieldInfos read(Directory directory, String segmentName, IOContext iocontext) throws IOException {
- final String fileName = IndexFileNames.segmentFileName(segmentName, "", FIELD_INFOS_EXTENSION);
+ public FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext iocontext) throws IOException {
+ final String fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
IndexInput input = directory.openInput(fileName, iocontext);
BytesRef scratch = new BytesRef();
@@ -104,6 +104,10 @@ public class SimpleTextFieldInfosReader extends FieldInfosReader {
String dvType = readString(DOCVALUES.length, scratch);
final DocValuesType docValuesType = docValuesType(dvType);
+ SimpleTextUtil.readLine(input, scratch);
+ assert StringHelper.startsWith(scratch, DOCVALUES_GEN);
+ final long dvGen = Long.parseLong(readString(DOCVALUES_GEN.length, scratch));
+
SimpleTextUtil.readLine(input, scratch);
assert StringHelper.startsWith(scratch, NUM_ATTS);
int numAtts = Integer.parseInt(readString(NUM_ATTS.length, scratch));
@@ -122,6 +126,7 @@ public class SimpleTextFieldInfosReader extends FieldInfosReader {
infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,
omitNorms, storePayloads, indexOptions, docValuesType, normsType, Collections.unmodifiableMap(atts));
+ infos[i].setDocValuesGen(dvGen);
}
if (input.getFilePointer() != input.length()) {
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java
index 9efd2edfe66..d9b50fcb89f 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java
@@ -53,14 +53,15 @@ public class SimpleTextFieldInfosWriter extends FieldInfosWriter {
static final BytesRef NORMS = new BytesRef(" norms ");
static final BytesRef NORMS_TYPE = new BytesRef(" norms type ");
static final BytesRef DOCVALUES = new BytesRef(" doc values ");
+ static final BytesRef DOCVALUES_GEN = new BytesRef(" doc values gen ");
static final BytesRef INDEXOPTIONS = new BytesRef(" index options ");
static final BytesRef NUM_ATTS = new BytesRef(" attributes ");
final static BytesRef ATT_KEY = new BytesRef(" key ");
final static BytesRef ATT_VALUE = new BytesRef(" value ");
@Override
- public void write(Directory directory, String segmentName, FieldInfos infos, IOContext context) throws IOException {
- final String fileName = IndexFileNames.segmentFileName(segmentName, "", FIELD_INFOS_EXTENSION);
+ public void write(Directory directory, String segmentName, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {
+ final String fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
IndexOutput out = directory.createOutput(fileName, context);
BytesRef scratch = new BytesRef();
boolean success = false;
@@ -108,6 +109,10 @@ public class SimpleTextFieldInfosWriter extends FieldInfosWriter {
SimpleTextUtil.write(out, DOCVALUES);
SimpleTextUtil.write(out, getDocValuesType(fi.getDocValuesType()), scratch);
SimpleTextUtil.writeNewline(out);
+
+ SimpleTextUtil.write(out, DOCVALUES_GEN);
+ SimpleTextUtil.write(out, Long.toString(fi.getDocValuesGen()), scratch);
+ SimpleTextUtil.writeNewline(out);
Map atts = fi.attributes();
int numAtts = atts == null ? 0 : atts.size();
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/Codec.java
index 3b98449eb5c..72b2e1e0a0b 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/Codec.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/Codec.java
@@ -119,7 +119,7 @@ public abstract class Codec implements NamedSPILoader.NamedSPI {
loader.reload(classloader);
}
- private static Codec defaultCodec = Codec.forName("Lucene45");
+ private static Codec defaultCodec = Codec.forName("Lucene46");
/** expert: returns the default codec used for newly created
* {@link IndexWriterConfig}s.
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java
index a817b4f7bd3..030fa5e893d 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java
@@ -35,5 +35,5 @@ public abstract class FieldInfosReader {
/** Read the {@link FieldInfos} previously written with {@link
* FieldInfosWriter}. */
- public abstract FieldInfos read(Directory directory, String segmentName, IOContext iocontext) throws IOException;
+ public abstract FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext iocontext) throws IOException;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java
index 17f2ae2c68a..e475b94db21 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java
@@ -35,5 +35,5 @@ public abstract class FieldInfosWriter {
/** Writes the provided {@link FieldInfos} to the
* directory. */
- public abstract void write(Directory directory, String segmentName, FieldInfos infos, IOContext context) throws IOException;
+ public abstract void write(Directory directory, String segmentName, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/FilterCodec.java b/lucene/core/src/java/org/apache/lucene/codecs/FilterCodec.java
index d97d577de22..93b34f97c7e 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/FilterCodec.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/FilterCodec.java
@@ -21,13 +21,13 @@ package org.apache.lucene.codecs;
* A codec that forwards all its method calls to another codec.
*
* Extend this class when you need to reuse the functionality of an existing
- * codec. For example, if you want to build a codec that redefines Lucene45's
+ * codec. For example, if you want to build a codec that redefines Lucene46's
* {@link LiveDocsFormat}:
*
* public final class CustomCodec extends FilterCodec {
*
* public CustomCodec() {
- * super("CustomCodec", new Lucene45Codec());
+ * super("CustomCodec", new Lucene46Codec());
* }
*
* public LiveDocsFormat liveDocsFormat() {
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java
index 2016063e538..a915e00622b 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java
@@ -49,7 +49,7 @@ class Lucene40FieldInfosReader extends FieldInfosReader {
}
@Override
- public FieldInfos read(Directory directory, String segmentName, IOContext iocontext) throws IOException {
+ public FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext iocontext) throws IOException {
final String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene40FieldInfosFormat.FIELD_INFOS_EXTENSION);
IndexInput input = directory.openInput(fileName, iocontext);
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42Codec.java
index 0ce97ba76e6..b88267c8663 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42Codec.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42Codec.java
@@ -95,7 +95,7 @@ public class Lucene42Codec extends Codec {
}
@Override
- public final FieldInfosFormat fieldInfosFormat() {
+ public FieldInfosFormat fieldInfosFormat() {
return fieldInfosFormat;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java
index c1559a37c66..5873bc0c4d5 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java
@@ -83,10 +83,11 @@ import org.apache.lucene.store.DataOutput; // javadoc
*
*
* @lucene.experimental
+ * @deprecated Only for reading old 4.2-4.5 segments
*/
-public final class Lucene42FieldInfosFormat extends FieldInfosFormat {
+@Deprecated
+public class Lucene42FieldInfosFormat extends FieldInfosFormat {
private final FieldInfosReader reader = new Lucene42FieldInfosReader();
- private final FieldInfosWriter writer = new Lucene42FieldInfosWriter();
/** Sole constructor. */
public Lucene42FieldInfosFormat() {
@@ -99,7 +100,7 @@ public final class Lucene42FieldInfosFormat extends FieldInfosFormat {
@Override
public FieldInfosWriter getFieldInfosWriter() throws IOException {
- return writer;
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
/** Extension of field infos */
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java
index 1beee5a90e7..16c07c1e64a 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java
@@ -38,8 +38,10 @@ import org.apache.lucene.util.IOUtils;
* Lucene 4.2 FieldInfos reader.
*
* @lucene.experimental
+ * @deprecated Only for reading old 4.2-4.5 segments
* @see Lucene42FieldInfosFormat
*/
+@Deprecated
final class Lucene42FieldInfosReader extends FieldInfosReader {
/** Sole constructor. */
@@ -47,7 +49,7 @@ final class Lucene42FieldInfosReader extends FieldInfosReader {
}
@Override
- public FieldInfos read(Directory directory, String segmentName, IOContext iocontext) throws IOException {
+ public FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext iocontext) throws IOException {
final String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene42FieldInfosFormat.EXTENSION);
IndexInput input = directory.openInput(fileName, iocontext);
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45Codec.java
index 5ec25e1003c..da25d63f08b 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45Codec.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45Codec.java
@@ -45,10 +45,12 @@ import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
*
* @see org.apache.lucene.codecs.lucene45 package documentation for file format details.
* @lucene.experimental
+ * @deprecated Only for reading old 4.3-4.5 segments
*/
// NOTE: if we make largish changes in a minor release, easier to just make Lucene46Codec or whatever
// if they are backwards compatible or smallish we can probably do the backwards in the postingsreader
// (it writes a minor version, etc).
+@Deprecated
public class Lucene45Codec extends Codec {
private final StoredFieldsFormat fieldsFormat = new Lucene41StoredFieldsFormat();
private final TermVectorsFormat vectorsFormat = new Lucene42TermVectorsFormat();
@@ -92,7 +94,7 @@ public class Lucene45Codec extends Codec {
}
@Override
- public final FieldInfosFormat fieldInfosFormat() {
+ public FieldInfosFormat fieldInfosFormat() {
return fieldInfosFormat;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java
new file mode 100755
index 00000000000..35329f8b505
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java
@@ -0,0 +1,139 @@
+package org.apache.lucene.codecs.lucene46;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.codecs.DocValuesFormat;
+import org.apache.lucene.codecs.FieldInfosFormat;
+import org.apache.lucene.codecs.FilterCodec;
+import org.apache.lucene.codecs.LiveDocsFormat;
+import org.apache.lucene.codecs.NormsFormat;
+import org.apache.lucene.codecs.PostingsFormat;
+import org.apache.lucene.codecs.SegmentInfoFormat;
+import org.apache.lucene.codecs.StoredFieldsFormat;
+import org.apache.lucene.codecs.TermVectorsFormat;
+import org.apache.lucene.codecs.lucene40.Lucene40LiveDocsFormat;
+import org.apache.lucene.codecs.lucene40.Lucene40SegmentInfoFormat;
+import org.apache.lucene.codecs.lucene41.Lucene41StoredFieldsFormat;
+import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
+import org.apache.lucene.codecs.lucene42.Lucene42TermVectorsFormat;
+import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;
+import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
+
+/**
+ * Implements the Lucene 4.6 index format, with configurable per-field postings
+ * and docvalues formats.
+ *
+ * If you want to reuse functionality of this codec in another codec, extend
+ * {@link FilterCodec}.
+ *
+ * @see org.apache.lucene.codecs.lucene46 package documentation for file format details.
+ * @lucene.experimental
+ */
+// NOTE: if we make largish changes in a minor release, easier to just make Lucene46Codec or whatever
+// if they are backwards compatible or smallish we can probably do the backwards in the postingsreader
+// (it writes a minor version, etc).
+public class Lucene46Codec extends Codec {
+ private final StoredFieldsFormat fieldsFormat = new Lucene41StoredFieldsFormat();
+ private final TermVectorsFormat vectorsFormat = new Lucene42TermVectorsFormat();
+ private final FieldInfosFormat fieldInfosFormat = new Lucene46FieldInfosFormat();
+ private final SegmentInfoFormat infosFormat = new Lucene40SegmentInfoFormat();
+ private final LiveDocsFormat liveDocsFormat = new Lucene40LiveDocsFormat();
+
+ private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {
+ @Override
+ public PostingsFormat getPostingsFormatForField(String field) {
+ return Lucene46Codec.this.getPostingsFormatForField(field);
+ }
+ };
+
+ private final DocValuesFormat docValuesFormat = new PerFieldDocValuesFormat() {
+ @Override
+ public DocValuesFormat getDocValuesFormatForField(String field) {
+ return Lucene46Codec.this.getDocValuesFormatForField(field);
+ }
+ };
+
+ /** Sole constructor. */
+ public Lucene46Codec() {
+ super("Lucene46");
+ }
+
+ @Override
+ public final StoredFieldsFormat storedFieldsFormat() {
+ return fieldsFormat;
+ }
+
+ @Override
+ public final TermVectorsFormat termVectorsFormat() {
+ return vectorsFormat;
+ }
+
+ @Override
+ public final PostingsFormat postingsFormat() {
+ return postingsFormat;
+ }
+
+ @Override
+ public final FieldInfosFormat fieldInfosFormat() {
+ return fieldInfosFormat;
+ }
+
+ @Override
+ public final SegmentInfoFormat segmentInfoFormat() {
+ return infosFormat;
+ }
+
+ @Override
+ public final LiveDocsFormat liveDocsFormat() {
+ return liveDocsFormat;
+ }
+
+ /** Returns the postings format that should be used for writing
+ * new segments of field
.
+ *
+ * The default implementation always returns "Lucene41"
+ */
+ public PostingsFormat getPostingsFormatForField(String field) {
+ return defaultFormat;
+ }
+
+ /** Returns the docvalues format that should be used for writing
+ * new segments of field
.
+ *
+ * The default implementation always returns "Lucene45"
+ */
+ public DocValuesFormat getDocValuesFormatForField(String field) {
+ return defaultDVFormat;
+ }
+
+ @Override
+ public final DocValuesFormat docValuesFormat() {
+ return docValuesFormat;
+ }
+
+ private final PostingsFormat defaultFormat = PostingsFormat.forName("Lucene41");
+ private final DocValuesFormat defaultDVFormat = DocValuesFormat.forName("Lucene45");
+
+ private final NormsFormat normsFormat = new Lucene42NormsFormat();
+
+ @Override
+ public final NormsFormat normsFormat() {
+ return normsFormat;
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java
new file mode 100755
index 00000000000..31101166cf8
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java
@@ -0,0 +1,126 @@
+package org.apache.lucene.codecs.lucene46;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.codecs.CodecUtil;
+import org.apache.lucene.codecs.DocValuesFormat;
+import org.apache.lucene.codecs.FieldInfosFormat;
+import org.apache.lucene.codecs.FieldInfosReader;
+import org.apache.lucene.codecs.FieldInfosWriter;
+import org.apache.lucene.index.FieldInfo.DocValuesType;
+import org.apache.lucene.store.DataOutput;
+
+/**
+ * Lucene 4.6 Field Infos format.
+ *
+ *
Field names are stored in the field info file, with suffix .fnm.
+ * FieldInfos (.fnm) --> Header,FieldsCount, <FieldName,FieldNumber,
+ * FieldBits,DocValuesBits,DocValuesGen,Attributes> FieldsCount
+ * Data types:
+ *
+ * - Header --> {@link CodecUtil#checkHeader CodecHeader}
+ * - FieldsCount --> {@link DataOutput#writeVInt VInt}
+ * - FieldName --> {@link DataOutput#writeString String}
+ * - FieldBits, DocValuesBits --> {@link DataOutput#writeByte Byte}
+ * - FieldNumber --> {@link DataOutput#writeInt VInt}
+ * - Attributes --> {@link DataOutput#writeStringStringMap Map<String,String>}
+ * - DocValuesGen --> {@link DataOutput#writeLong(long) Int64}
+ *
+ *
+ * Field Descriptions:
+ *
+ * - FieldsCount: the number of fields in this file.
+ * - FieldName: name of the field as a UTF-8 String.
+ * - FieldNumber: the field's number. Note that unlike previous versions of
+ * Lucene, the fields are not numbered implicitly by their order in the
+ * file, instead explicitly.
+ * - FieldBits: a byte containing field options.
+ *
+ * - The low-order bit is one for indexed fields, and zero for non-indexed
+ * fields.
+ * - The second lowest-order bit is one for fields that have term vectors
+ * stored, and zero for fields without term vectors.
+ * - If the third lowest order-bit is set (0x4), offsets are stored into
+ * the postings list in addition to positions.
+ * - Fourth bit is unused.
+ * - If the fifth lowest-order bit is set (0x10), norms are omitted for the
+ * indexed field.
+ * - If the sixth lowest-order bit is set (0x20), payloads are stored for the
+ * indexed field.
+ * - If the seventh lowest-order bit is set (0x40), term frequencies and
+ * positions omitted for the indexed field.
+ * - If the eighth lowest-order bit is set (0x80), positions are omitted for the
+ * indexed field.
+ *
+ *
+ * - DocValuesBits: a byte containing per-document value types. The type
+ * recorded as two four-bit integers, with the high-order bits representing
+ *
norms
options, and the low-order bits representing
+ * {@code DocValues} options. Each four-bit integer can be decoded as such:
+ *
+ * - 0: no DocValues for this field.
+ * - 1: NumericDocValues. ({@link DocValuesType#NUMERIC})
+ * - 2: BinaryDocValues. ({@code DocValuesType#BINARY})
+ * - 3: SortedDocValues. ({@code DocValuesType#SORTED})
+ *
+ *
+ * - DocValuesGen is the generation count of the field's DocValues. If this is -1,
+ * there are no DocValues updates to that field. Anything above zero means there
+ * are updates stored by {@link DocValuesFormat}.
+ * - Attributes: a key-value map of codec-private attributes.
+ *
+ *
+ * @lucene.experimental
+ */
+public final class Lucene46FieldInfosFormat extends FieldInfosFormat {
+ private final FieldInfosReader reader = new Lucene46FieldInfosReader();
+ private final FieldInfosWriter writer = new Lucene46FieldInfosWriter();
+
+ /** Sole constructor. */
+ public Lucene46FieldInfosFormat() {
+ }
+
+ @Override
+ public FieldInfosReader getFieldInfosReader() throws IOException {
+ return reader;
+ }
+
+ @Override
+ public FieldInfosWriter getFieldInfosWriter() throws IOException {
+ return writer;
+ }
+
+ /** Extension of field infos */
+ static final String EXTENSION = "fnm";
+
+ // Codec header
+ static final String CODEC_NAME = "Lucene46FieldInfos";
+ static final int FORMAT_START = 0;
+ static final int FORMAT_CURRENT = FORMAT_START;
+
+ // Field flags
+ static final byte IS_INDEXED = 0x1;
+ static final byte STORE_TERMVECTOR = 0x2;
+ static final byte STORE_OFFSETS_IN_POSTINGS = 0x4;
+ static final byte OMIT_NORMS = 0x10;
+ static final byte STORE_PAYLOADS = 0x20;
+ static final byte OMIT_TERM_FREQ_AND_POSITIONS = 0x40;
+ static final byte OMIT_POSITIONS = -128;
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java
new file mode 100755
index 00000000000..ee9a7dc2071
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java
@@ -0,0 +1,125 @@
+package org.apache.lucene.codecs.lucene46;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.lucene.codecs.CodecUtil;
+import org.apache.lucene.codecs.FieldInfosReader;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.IndexFileNames;
+import org.apache.lucene.index.FieldInfo.DocValuesType;
+import org.apache.lucene.index.FieldInfo.IndexOptions;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.IOUtils;
+
+/**
+ * Lucene 4.6 FieldInfos reader.
+ *
+ * @lucene.experimental
+ * @see Lucene46FieldInfosFormat
+ */
+final class Lucene46FieldInfosReader extends FieldInfosReader {
+
+ /** Sole constructor. */
+ public Lucene46FieldInfosReader() {
+ }
+
+ @Override
+ public FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext context) throws IOException {
+ final String fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION);
+ IndexInput input = directory.openInput(fileName, context);
+
+ boolean success = false;
+ try {
+ CodecUtil.checkHeader(input, Lucene46FieldInfosFormat.CODEC_NAME,
+ Lucene46FieldInfosFormat.FORMAT_START,
+ Lucene46FieldInfosFormat.FORMAT_CURRENT);
+
+ final int size = input.readVInt(); //read in the size
+ FieldInfo infos[] = new FieldInfo[size];
+
+ for (int i = 0; i < size; i++) {
+ String name = input.readString();
+ final int fieldNumber = input.readVInt();
+ byte bits = input.readByte();
+ boolean isIndexed = (bits & Lucene46FieldInfosFormat.IS_INDEXED) != 0;
+ boolean storeTermVector = (bits & Lucene46FieldInfosFormat.STORE_TERMVECTOR) != 0;
+ boolean omitNorms = (bits & Lucene46FieldInfosFormat.OMIT_NORMS) != 0;
+ boolean storePayloads = (bits & Lucene46FieldInfosFormat.STORE_PAYLOADS) != 0;
+ final IndexOptions indexOptions;
+ if (!isIndexed) {
+ indexOptions = null;
+ } else if ((bits & Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {
+ indexOptions = IndexOptions.DOCS_ONLY;
+ } else if ((bits & Lucene46FieldInfosFormat.OMIT_POSITIONS) != 0) {
+ indexOptions = IndexOptions.DOCS_AND_FREQS;
+ } else if ((bits & Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {
+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+ } else {
+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
+ }
+
+ // DV Types are packed in one byte
+ byte val = input.readByte();
+ final DocValuesType docValuesType = getDocValuesType(input, (byte) (val & 0x0F));
+ final DocValuesType normsType = getDocValuesType(input, (byte) ((val >>> 4) & 0x0F));
+ final long dvGen = input.readLong();
+ final Map attributes = input.readStringStringMap();
+ infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,
+ omitNorms, storePayloads, indexOptions, docValuesType, normsType, Collections.unmodifiableMap(attributes));
+ infos[i].setDocValuesGen(dvGen);
+ }
+
+ if (input.getFilePointer() != input.length()) {
+ throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
+ }
+ FieldInfos fieldInfos = new FieldInfos(infos);
+ success = true;
+ return fieldInfos;
+ } finally {
+ if (success) {
+ input.close();
+ } else {
+ IOUtils.closeWhileHandlingException(input);
+ }
+ }
+ }
+
+ private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {
+ if (b == 0) {
+ return null;
+ } else if (b == 1) {
+ return DocValuesType.NUMERIC;
+ } else if (b == 2) {
+ return DocValuesType.BINARY;
+ } else if (b == 3) {
+ return DocValuesType.SORTED;
+ } else if (b == 4) {
+ return DocValuesType.SORTED_SET;
+ } else {
+ throw new CorruptIndexException("invalid docvalues byte: " + b + " (resource=" + input + ")");
+ }
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java
new file mode 100755
index 00000000000..e7b051808ba
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java
@@ -0,0 +1,109 @@
+package org.apache.lucene.codecs.lucene46;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.codecs.CodecUtil;
+import org.apache.lucene.codecs.FieldInfosWriter;
+import org.apache.lucene.index.FieldInfo.DocValuesType;
+import org.apache.lucene.index.FieldInfo.IndexOptions;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.IndexFileNames;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.IOUtils;
+
+/**
+ * Lucene 4.6 FieldInfos writer.
+ *
+ * @see Lucene46FieldInfosFormat
+ * @lucene.experimental
+ */
+final class Lucene46FieldInfosWriter extends FieldInfosWriter {
+
+ /** Sole constructor. */
+ public Lucene46FieldInfosWriter() {
+ }
+
+ @Override
+ public void write(Directory directory, String segmentName, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {
+ final String fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION);
+ IndexOutput output = directory.createOutput(fileName, context);
+ boolean success = false;
+ try {
+ CodecUtil.writeHeader(output, Lucene46FieldInfosFormat.CODEC_NAME, Lucene46FieldInfosFormat.FORMAT_CURRENT);
+ output.writeVInt(infos.size());
+ for (FieldInfo fi : infos) {
+ IndexOptions indexOptions = fi.getIndexOptions();
+ byte bits = 0x0;
+ if (fi.hasVectors()) bits |= Lucene46FieldInfosFormat.STORE_TERMVECTOR;
+ if (fi.omitsNorms()) bits |= Lucene46FieldInfosFormat.OMIT_NORMS;
+ if (fi.hasPayloads()) bits |= Lucene46FieldInfosFormat.STORE_PAYLOADS;
+ if (fi.isIndexed()) {
+ bits |= Lucene46FieldInfosFormat.IS_INDEXED;
+ assert indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();
+ if (indexOptions == IndexOptions.DOCS_ONLY) {
+ bits |= Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;
+ } else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {
+ bits |= Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;
+ } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) {
+ bits |= Lucene46FieldInfosFormat.OMIT_POSITIONS;
+ }
+ }
+ output.writeString(fi.name);
+ output.writeVInt(fi.number);
+ output.writeByte(bits);
+
+ // pack the DV types in one byte
+ final byte dv = docValuesByte(fi.getDocValuesType());
+ final byte nrm = docValuesByte(fi.getNormType());
+ assert (dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0;
+ byte val = (byte) (0xff & ((nrm << 4) | dv));
+ output.writeByte(val);
+ output.writeLong(fi.getDocValuesGen());
+ output.writeStringStringMap(fi.attributes());
+ }
+ success = true;
+ } finally {
+ if (success) {
+ output.close();
+ } else {
+ IOUtils.closeWhileHandlingException(output);
+ }
+ }
+ }
+
+ private static byte docValuesByte(DocValuesType type) {
+ if (type == null) {
+ return 0;
+ } else if (type == DocValuesType.NUMERIC) {
+ return 1;
+ } else if (type == DocValuesType.BINARY) {
+ return 2;
+ } else if (type == DocValuesType.SORTED) {
+ return 3;
+ } else if (type == DocValuesType.SORTED_SET) {
+ return 4;
+ } else {
+ throw new AssertionError();
+ }
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html
new file mode 100755
index 00000000000..3bc457b0d6e
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html
@@ -0,0 +1,398 @@
+
+
+
+
+
+
+
+Lucene 4.6 file format.
+
+Apache Lucene - Index File Formats
+
+
+Introduction
+
+
This document defines the index file formats used in this version of Lucene.
+If you are using a different version of Lucene, please consult the copy of
+docs/
that was distributed with
+the version you are using.
+
Apache Lucene is written in Java, but several efforts are underway to write
+versions of
+Lucene in other programming languages. If these versions are to remain
+compatible with Apache Lucene, then a language-independent definition of the
+Lucene index format is required. This document thus attempts to provide a
+complete and independent definition of the Apache Lucene file formats.
+
As Lucene evolves, this document should evolve. Versions of Lucene in
+different programming languages should endeavor to agree on file formats, and
+generate new versions of this document.
+
+
+Definitions
+
+
The fundamental concepts in Lucene are index, document, field and term.
+
An index contains a sequence of documents.
+
+- A document is a sequence of fields.
+- A field is a named sequence of terms.
+- A term is a sequence of bytes.
+
+
The same sequence of bytes in two different fields is considered a different
+term. Thus terms are represented as a pair: the string naming the field, and the
+bytes within the field.
+
+
Inverted Indexing
+
The index stores statistics about terms in order to make term-based search
+more efficient. Lucene's index falls into the family of indexes known as an
+inverted index. This is because it can list, for a term, the documents
+that contain it. This is the inverse of the natural relationship, in which
+documents list terms.
+
+
Types of Fields
+
In Lucene, fields may be stored, in which case their text is stored
+in the index literally, in a non-inverted manner. Fields that are inverted are
+called indexed. A field may be both stored and indexed.
+
The text of a field may be tokenized into terms to be indexed, or the
+text of a field may be used literally as a term to be indexed. Most fields are
+tokenized, but sometimes it is useful for certain identifier fields to be
+indexed literally.
+
See the {@link org.apache.lucene.document.Field Field}
+java docs for more information on Fields.
+
+
Segments
+
Lucene indexes may be composed of multiple sub-indexes, or segments.
+Each segment is a fully independent index, which could be searched separately.
+Indexes evolve by:
+
+- Creating new segments for newly added documents.
+- Merging existing segments.
+
+
Searches may involve multiple segments and/or multiple indexes, each index
+potentially composed of a set of segments.
+
+
Document Numbers
+
Internally, Lucene refers to documents by an integer document number.
+The first document added to an index is numbered zero, and each subsequent
+document added gets a number one greater than the previous.
+
Note that a document's number may change, so caution should be taken when
+storing these numbers outside of Lucene. In particular, numbers may change in
+the following situations:
+
+-
+
The numbers stored in each segment are unique only within the segment, and
+must be converted before they can be used in a larger context. The standard
+technique is to allocate each segment a range of values, based on the range of
+numbers used in that segment. To convert a document number from a segment to an
+external value, the segment's base document number is added. To convert
+an external value back to a segment-specific value, the segment is identified
+by the range that the external value is in, and the segment's base value is
+subtracted. For example two five document segments might be combined, so that
+the first segment has a base value of zero, and the second of five. Document
+three from the second segment would have an external value of eight.
+
+-
+
When documents are deleted, gaps are created in the numbering. These are
+eventually removed as the index evolves through merging. Deleted documents are
+dropped when segments are merged. A freshly-merged segment thus has no gaps in
+its numbering.
+
+
+
+
+Index Structure Overview
+
+
Each segment index maintains the following:
+
+-
+{@link org.apache.lucene.codecs.lucene40.Lucene40SegmentInfoFormat Segment info}.
+ This contains metadata about a segment, such as the number of documents,
+ what files it uses,
+
+-
+{@link org.apache.lucene.codecs.lucene46.Lucene46FieldInfosFormat Field names}.
+ This contains the set of field names used in the index.
+
+-
+{@link org.apache.lucene.codecs.lucene41.Lucene41StoredFieldsFormat Stored Field values}.
+This contains, for each document, a list of attribute-value pairs, where the attributes
+are field names. These are used to store auxiliary information about the document, such as
+its title, url, or an identifier to access a database. The set of stored fields are what is
+returned for each hit when searching. This is keyed by document number.
+
+-
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Term dictionary}.
+A dictionary containing all of the terms used in all of the
+indexed fields of all of the documents. The dictionary also contains the number
+of documents which contain the term, and pointers to the term's frequency and
+proximity data.
+
+-
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Term Frequency data}.
+For each term in the dictionary, the numbers of all the
+documents that contain that term, and the frequency of the term in that
+document, unless frequencies are omitted (IndexOptions.DOCS_ONLY)
+
+-
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Term Proximity data}.
+For each term in the dictionary, the positions that the
+term occurs in each document. Note that this will not exist if all fields in
+all documents omit position data.
+
+-
+{@link org.apache.lucene.codecs.lucene42.Lucene42NormsFormat Normalization factors}.
+For each field in each document, a value is stored
+that is multiplied into the score for hits on that field.
+
+-
+{@link org.apache.lucene.codecs.lucene42.Lucene42TermVectorsFormat Term Vectors}.
+For each field in each document, the term vector (sometimes
+called document vector) may be stored. A term vector consists of term text and
+term frequency. To add Term Vectors to your index see the
+{@link org.apache.lucene.document.Field Field} constructors
+
+-
+{@link org.apache.lucene.codecs.lucene42.Lucene42DocValuesFormat Per-document values}.
+Like stored values, these are also keyed by document
+number, but are generally intended to be loaded into main memory for fast
+access. Whereas stored values are generally intended for summary results from
+searches, per-document values are useful for things like scoring factors.
+
+-
+{@link org.apache.lucene.codecs.lucene40.Lucene40LiveDocsFormat Deleted documents}.
+An optional file indicating which documents are deleted.
+
+
+
Details on each of these are provided in their linked pages.
+
+
+File Naming
+
+
All files belonging to a segment have the same name with varying extensions.
+The extensions correspond to the different file formats described below. When
+using the Compound File format (default in 1.4 and greater) these files (except
+for the Segment info file, the Lock file, and Deleted documents file) are collapsed
+into a single .cfs file (see below for details)
+
Typically, all segments in an index are stored in a single directory,
+although this is not required.
+
As of version 2.1 (lock-less commits), file names are never re-used (there
+is one exception, "segments.gen", see below). That is, when any file is saved
+to the Directory it is given a never before used filename. This is achieved
+using a simple generations approach. For example, the first segments file is
+segments_1, then segments_2, etc. The generation is a sequential long integer
+represented in alpha-numeric (base 36) form.
+
+
+Summary of File Extensions
+
+
The following table summarizes the names and extensions of the files in
+Lucene:
+
+
+Name |
+Extension |
+Brief Description |
+
+
+{@link org.apache.lucene.index.SegmentInfos Segments File} |
+segments.gen, segments_N |
+Stores information about a commit point |
+
+
+Lock File |
+write.lock |
+The Write lock prevents multiple IndexWriters from writing to the same
+file. |
+
+
+{@link org.apache.lucene.codecs.lucene40.Lucene40SegmentInfoFormat Segment Info} |
+.si |
+Stores metadata about a segment |
+
+
+{@link org.apache.lucene.store.CompoundFileDirectory Compound File} |
+.cfs, .cfe |
+An optional "virtual" file consisting of all the other index files for
+systems that frequently run out of file handles. |
+
+
+{@link org.apache.lucene.codecs.lucene46.Lucene46FieldInfosFormat Fields} |
+.fnm |
+Stores information about the fields |
+
+
+{@link org.apache.lucene.codecs.lucene41.Lucene41StoredFieldsFormat Field Index} |
+.fdx |
+Contains pointers to field data |
+
+
+{@link org.apache.lucene.codecs.lucene41.Lucene41StoredFieldsFormat Field Data} |
+.fdt |
+The stored fields for documents |
+
+
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Term Dictionary} |
+.tim |
+The term dictionary, stores term info |
+
+
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Term Index} |
+.tip |
+The index into the Term Dictionary |
+
+
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Frequencies} |
+.doc |
+Contains the list of docs which contain each term along with frequency |
+
+
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Positions} |
+.pos |
+Stores position information about where a term occurs in the index |
+
+
+{@link org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat Payloads} |
+.pay |
+Stores additional per-position metadata information such as character offsets and user payloads |
+
+
+{@link org.apache.lucene.codecs.lucene42.Lucene42NormsFormat Norms} |
+.nvd, .nvm |
+Encodes length and boost factors for docs and fields |
+
+
+{@link org.apache.lucene.codecs.lucene42.Lucene42DocValuesFormat Per-Document Values} |
+.dvd, .dvm |
+Encodes additional scoring factors or other per-document information. |
+
+
+{@link org.apache.lucene.codecs.lucene42.Lucene42TermVectorsFormat Term Vector Index} |
+.tvx |
+Stores offset into the document data file |
+
+
+{@link org.apache.lucene.codecs.lucene42.Lucene42TermVectorsFormat Term Vector Documents} |
+.tvd |
+Contains information about each document that has term vectors |
+
+
+{@link org.apache.lucene.codecs.lucene42.Lucene42TermVectorsFormat Term Vector Fields} |
+.tvf |
+The field level info about term vectors |
+
+
+{@link org.apache.lucene.codecs.lucene40.Lucene40LiveDocsFormat Deleted Documents} |
+.del |
+Info about what files are deleted |
+
+
+
+
+Lock File
+The write lock, which is stored in the index directory by default, is named
+"write.lock". If the lock directory is different from the index directory then
+the write lock will be named "XXXX-write.lock" where XXXX is a unique prefix
+derived from the full path to the index directory. When this file is present, a
+writer is currently modifying the index (adding or removing documents). This
+lock file ensures that only one writer is modifying the index at a time.
+
+History
+Compatibility notes are provided in this document, describing how file
+formats have changed from prior versions:
+
+- In version 2.1, the file format was changed to allow lock-less commits (ie,
+no more commit lock). The change is fully backwards compatible: you can open a
+pre-2.1 index for searching or adding/deleting of docs. When the new segments
+file is saved (committed), it will be written in the new file format (meaning
+no specific "upgrade" process is needed). But note that once a commit has
+occurred, pre-2.1 Lucene will not be able to read the index.
+- In version 2.3, the file format was changed to allow segments to share a
+single set of doc store (vectors & stored fields) files. This allows for
+faster indexing in certain cases. The change is fully backwards compatible (in
+the same way as the lock-less commits change in 2.1).
+- In version 2.4, Strings are now written as true UTF-8 byte sequence, not
+Java's modified UTF-8. See
+LUCENE-510 for details.
+- In version 2.9, an optional opaque Map<String,String> CommitUserData
+may be passed to IndexWriter's commit methods (and later retrieved), which is
+recorded in the segments_N file. See
+LUCENE-1382 for details. Also,
+diagnostics were added to each segment written recording details about why it
+was written (due to flush, merge; which OS/JRE was used; etc.). See issue
+LUCENE-1654 for details.
+- In version 3.0, compressed fields are no longer written to the index (they
+can still be read, but on merge the new segment will write them, uncompressed).
+See issue LUCENE-1960
+for details.
+- In version 3.1, segments records the code version that created them. See
+LUCENE-2720 for details.
+Additionally segments track explicitly whether or not they have term vectors.
+See LUCENE-2811
+for details.
+- In version 3.2, numeric fields are written as natively to stored fields
+file, previously they were stored in text format only.
+- In version 3.4, fields can omit position data while still indexing term
+frequencies.
+- In version 4.0, the format of the inverted index became extensible via
+the {@link org.apache.lucene.codecs.Codec Codec} api. Fast per-document storage
+({@code DocValues}) was introduced. Normalization factors need no longer be a
+single byte, they can be any {@link org.apache.lucene.index.NumericDocValues NumericDocValues}.
+Terms need not be unicode strings, they can be any byte sequence. Term offsets
+can optionally be indexed into the postings lists. Payloads can be stored in the
+term vectors.
+- In version 4.1, the format of the postings list changed to use either
+of FOR compression or variable-byte encoding, depending upon the frequency
+of the term. Terms appearing only once were changed to inline directly into
+the term dictionary. Stored fields are compressed by default.
+- In version 4.2, term vectors are compressed by default. DocValues has
+a new multi-valued type (SortedSet), that can be used for faceting/grouping/joining
+on multi-valued fields.
+- In version 4.5, DocValues were extended to explicitly represent missing values.
+- In version 4.6, FieldInfos were extended to support per-field DocValues generation, to
+allow updating NumericDocValues fields.
+
+
+Limitations
+
+
Lucene uses a Java int
to refer to
+document numbers, and the index file format uses an Int32
+on-disk to store document numbers. This is a limitation
+of both the index file format and the current implementation. Eventually these
+should be replaced with either UInt64
values, or
+better yet, {@link org.apache.lucene.store.DataOutput#writeVInt VInt} values which have no limit.
+
+
+
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/package.html b/lucene/core/src/java/org/apache/lucene/codecs/package.html
index 16f53b5cdde..9081764c950 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/package.html
+++ b/lucene/core/src/java/org/apache/lucene/codecs/package.html
@@ -61,13 +61,13 @@ name of your codec.
If you just want to customise the {@link org.apache.lucene.codecs.PostingsFormat}, or use different postings
formats for different fields, then you can register your custom postings format in the same way (in
META-INF/services/org.apache.lucene.codecs.PostingsFormat), and then extend the default
- {@link org.apache.lucene.codecs.lucene45.Lucene45Codec} and override
- {@link org.apache.lucene.codecs.lucene45.Lucene45Codec#getPostingsFormatForField(String)} to return your custom
+ {@link org.apache.lucene.codecs.lucene46.Lucene46Codec} and override
+ {@link org.apache.lucene.codecs.lucene46.Lucene46Codec#getPostingsFormatForField(String)} to return your custom
postings format.
Similarly, if you just want to customise the {@link org.apache.lucene.codecs.DocValuesFormat} per-field, have
- a look at {@link org.apache.lucene.codecs.lucene45.Lucene45Codec#getDocValuesFormatForField(String)}.
+ a look at {@link org.apache.lucene.codecs.lucene46.Lucene46Codec#getDocValuesFormatForField(String)}.