Index: lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java (revision 1535645)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java (working copy)
@@ -17,6 +17,16 @@
* limitations under the License.
*/
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.END;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.FIELD;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.LENGTH;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MAXLENGTH;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MINVALUE;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.NUMVALUES;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.ORDPATTERN;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.PATTERN;
+import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.TYPE;
+
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -31,11 +41,11 @@
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.Bits;
@@ -42,16 +52,6 @@
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.StringHelper;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.END;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.FIELD;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.LENGTH;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MAXLENGTH;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.MINVALUE;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.NUMVALUES;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.ORDPATTERN;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.PATTERN;
-import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.TYPE;
-
class SimpleTextDocValuesReader extends DocValuesProducer {
static class OneField {
@@ -62,8 +62,7 @@
boolean fixedLength;
long minValue;
long numValues;
-
- };
+ }
final int maxDoc;
final IndexInput data;
@@ -71,7 +70,7 @@
final Map fields = new HashMap();
public SimpleTextDocValuesReader(SegmentReadState state, String ext) throws IOException {
- //System.out.println("dir=" + state.directory + " seg=" + state.segmentInfo.name + " ext=" + ext);
+ // System.out.println("dir=" + state.directory + " seg=" + state.segmentInfo.name + " file=" + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext));
data = state.directory.openInput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
maxDoc = state.segmentInfo.getDocCount();
while(true) {
@@ -83,8 +82,6 @@
assert startsWith(FIELD) : scratch.utf8ToString();
String fieldName = stripPrefix(FIELD);
//System.out.println(" field=" + fieldName);
- FieldInfo fieldInfo = state.fieldInfos.fieldInfo(fieldName);
- assert fieldInfo != null;
OneField field = new OneField();
fields.put(fieldName, field);
Index: lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesWriter.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesWriter.java (revision 1535645)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesWriter.java (working copy)
@@ -55,7 +55,7 @@
private final Set fieldsSeen = new HashSet(); // for asserting
public SimpleTextDocValuesWriter(SegmentWriteState state, String ext) throws IOException {
- //System.out.println("WRITE: " + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext) + " " + state.segmentInfo.getDocCount() + " docs");
+ // System.out.println("WRITE: " + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext) + " " + state.segmentInfo.getDocCount() + " docs");
data = state.directory.createOutput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
numDocs = state.segmentInfo.getDocCount();
}
Index: lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java (revision 1535645)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java (working copy)
@@ -47,8 +47,8 @@
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();
@@ -105,6 +105,10 @@
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));
Map atts = new HashMap();
@@ -122,6 +126,7 @@
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()) {
Index: lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java (revision 1535645)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java (working copy)
@@ -53,6 +53,7 @@
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 ");
@@ -59,8 +60,8 @@
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 @@
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();
Index: lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java (revision 1535645)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java (working copy)
@@ -17,8 +17,16 @@
* limitations under the License.
*/
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DIAG_KEY;
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DIAG_VALUE;
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DOCCOUNT;
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_FILE;
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_NUM_DIAG;
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_NUM_FILES;
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_USECOMPOUND;
+import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_VERSION;
+
import java.io.IOException;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -34,8 +42,6 @@
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.StringHelper;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.*;
-
/**
* reads plaintext segments files
*
@@ -80,22 +86,6 @@
}
SimpleTextUtil.readLine(input, scratch);
- assert StringHelper.startsWith(scratch, SI_NUM_ATTS);
- int numAtts = Integer.parseInt(readString(SI_NUM_ATTS.length, scratch));
- Map attributes = new HashMap();
-
- for (int i = 0; i < numAtts; i++) {
- SimpleTextUtil.readLine(input, scratch);
- assert StringHelper.startsWith(scratch, SI_ATT_KEY);
- String key = readString(SI_ATT_KEY.length, scratch);
-
- SimpleTextUtil.readLine(input, scratch);
- assert StringHelper.startsWith(scratch, SI_ATT_VALUE);
- String value = readString(SI_ATT_VALUE.length, scratch);
- attributes.put(key, value);
- }
-
- SimpleTextUtil.readLine(input, scratch);
assert StringHelper.startsWith(scratch, SI_NUM_FILES);
int numFiles = Integer.parseInt(readString(SI_NUM_FILES.length, scratch));
Set files = new HashSet();
@@ -108,7 +98,7 @@
}
SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,
- isCompoundFile, null, diagnostics, Collections.unmodifiableMap(attributes));
+ isCompoundFile, null, diagnostics);
info.setFiles(files);
success = true;
return info;
Index: lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoWriter.java
===================================================================
--- lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoWriter.java (revision 1535645)
+++ lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoWriter.java (working copy)
@@ -45,9 +45,6 @@
final static BytesRef SI_NUM_DIAG = new BytesRef(" diagnostics ");
final static BytesRef SI_DIAG_KEY = new BytesRef(" key ");
final static BytesRef SI_DIAG_VALUE = new BytesRef(" value ");
- final static BytesRef SI_NUM_ATTS = new BytesRef(" attributes ");
- final static BytesRef SI_ATT_KEY = new BytesRef(" key ");
- final static BytesRef SI_ATT_VALUE = new BytesRef(" value ");
final static BytesRef SI_NUM_FILES = new BytesRef(" files ");
final static BytesRef SI_FILE = new BytesRef(" file ");
@@ -93,24 +90,6 @@
}
}
- Map atts = si.attributes();
- int numAtts = atts == null ? 0 : atts.size();
- SimpleTextUtil.write(output, SI_NUM_ATTS);
- SimpleTextUtil.write(output, Integer.toString(numAtts), scratch);
- SimpleTextUtil.writeNewline(output);
-
- if (numAtts > 0) {
- for (Map.Entry entry : atts.entrySet()) {
- SimpleTextUtil.write(output, SI_ATT_KEY);
- SimpleTextUtil.write(output, entry.getKey(), scratch);
- SimpleTextUtil.writeNewline(output);
-
- SimpleTextUtil.write(output, SI_ATT_VALUE);
- SimpleTextUtil.write(output, entry.getValue(), scratch);
- SimpleTextUtil.writeNewline(output);
- }
- }
-
Set files = si.files();
int numFiles = files == null ? 0 : files.size();
SimpleTextUtil.write(output, SI_NUM_FILES);
Index: lucene/codecs
===================================================================
--- lucene/codecs (revision 1535645)
+++ lucene/codecs (working copy)
Property changes on: lucene/codecs
___________________________________________________________________
Modified: svn:mergeinfo
Merged /lucene/dev/trunk/lucene/codecs:r1523461,1527154,1527391
Index: lucene/core/src/java/org/apache/lucene/codecs/Codec.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/Codec.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/Codec.java (working copy)
@@ -119,7 +119,7 @@
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.
Index: lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java (working copy)
@@ -35,5 +35,5 @@
/** 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;
}
Index: lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java (working copy)
@@ -35,5 +35,5 @@
/** 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;
}
Index: lucene/core/src/java/org/apache/lucene/codecs/FilterCodec.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/FilterCodec.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/FilterCodec.java (working copy)
@@ -21,13 +21,13 @@
* 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() {
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosReader.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xFieldInfosReader.java (working copy)
@@ -57,7 +57,7 @@
static final byte OMIT_POSITIONS = -128;
@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, "", FIELD_INFOS_EXTENSION);
IndexInput input = directory.openInput(fileName, iocontext);
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java (working copy)
@@ -244,7 +244,7 @@
null, diagnostics, Collections.unmodifiableMap(attributes));
info.setFiles(files);
- SegmentInfoPerCommit infoPerCommit = new SegmentInfoPerCommit(info, delCount, delGen);
+ SegmentInfoPerCommit infoPerCommit = new SegmentInfoPerCommit(info, delCount, delGen, -1);
return infoPerCommit;
}
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40Codec.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40Codec.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40Codec.java (working copy)
@@ -82,7 +82,7 @@
}
@Override
- public final SegmentInfoFormat segmentInfoFormat() {
+ public SegmentInfoFormat segmentInfoFormat() {
return infosFormat;
}
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java (working copy)
@@ -49,7 +49,7 @@
}
@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);
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java (working copy)
@@ -67,10 +67,11 @@
*
* @see SegmentInfos
* @lucene.experimental
+ * @deprecated Only for reading old 4.0-4.5 segments
*/
+@Deprecated
public class Lucene40SegmentInfoFormat extends SegmentInfoFormat {
private final SegmentInfoReader reader = new Lucene40SegmentInfoReader();
- private final SegmentInfoWriter writer = new Lucene40SegmentInfoWriter();
/** Sole constructor. */
public Lucene40SegmentInfoFormat() {
@@ -83,7 +84,7 @@
@Override
public SegmentInfoWriter getSegmentInfoWriter() {
- return writer;
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
/** File extension used to store {@link SegmentInfo}. */
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java (working copy)
@@ -18,7 +18,6 @@
*/
import java.io.IOException;
-import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -37,7 +36,9 @@
*
* @see Lucene40SegmentInfoFormat
* @lucene.experimental
+ * @deprecated Only for reading old 4.0-4.5 segments
*/
+@Deprecated
public class Lucene40SegmentInfoReader extends SegmentInfoReader {
/** Sole constructor. */
@@ -60,7 +61,7 @@
}
final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
final Map diagnostics = input.readStringStringMap();
- final Map attributes = input.readStringStringMap();
+ input.readStringStringMap(); // read deprecated attributes
final Set files = input.readStringSet();
if (input.getFilePointer() != input.length()) {
@@ -67,8 +68,7 @@
throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
}
- final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile,
- null, diagnostics, Collections.unmodifiableMap(attributes));
+ final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics);
si.setFiles(files);
success = true;
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java (working copy)
@@ -1,74 +0,0 @@
-package org.apache.lucene.codecs.lucene40;
-
-/*
- * 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.SegmentInfoWriter;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-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.0 implementation of {@link SegmentInfoWriter}.
- *
- * @see Lucene40SegmentInfoFormat
- * @lucene.experimental
- */
-public class Lucene40SegmentInfoWriter extends SegmentInfoWriter {
-
- /** Sole constructor. */
- public Lucene40SegmentInfoWriter() {
- }
-
- /** Save a single segment's info. */
- @Override
- public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
- final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene40SegmentInfoFormat.SI_EXTENSION);
- si.addFile(fileName);
-
- final IndexOutput output = dir.createOutput(fileName, ioContext);
-
- boolean success = false;
- try {
- CodecUtil.writeHeader(output, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_CURRENT);
- // Write the Lucene version that created this segment, since 3.1
- output.writeString(si.getVersion());
- output.writeInt(si.getDocCount());
-
- output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
- output.writeStringStringMap(si.getDiagnostics());
- output.writeStringStringMap(si.attributes());
- output.writeStringSet(si.files());
-
- success = true;
- } finally {
- if (!success) {
- IOUtils.closeWhileHandlingException(output);
- si.dir.deleteFile(fileName);
- } else {
- output.close();
- }
- }
- }
-}
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java (working copy)
@@ -101,7 +101,7 @@
}
@Override
- public final SegmentInfoFormat segmentInfoFormat() {
+ public SegmentInfoFormat segmentInfoFormat() {
return infosFormat;
}
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42Codec.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42Codec.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42Codec.java (working copy)
@@ -95,12 +95,12 @@
}
@Override
- public final FieldInfosFormat fieldInfosFormat() {
+ public FieldInfosFormat fieldInfosFormat() {
return fieldInfosFormat;
}
@Override
- public final SegmentInfoFormat segmentInfoFormat() {
+ public SegmentInfoFormat segmentInfoFormat() {
return infosFormat;
}
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java (working copy)
@@ -83,10 +83,11 @@
*
*
* @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 @@
@Override
public FieldInfosWriter getFieldInfosWriter() throws IOException {
- return writer;
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
/** Extension of field infos */
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java (working copy)
@@ -38,8 +38,10 @@
* 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 @@
}
@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);
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosWriter.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosWriter.java (working copy)
@@ -1,108 +0,0 @@
-package org.apache.lucene.codecs.lucene42;
-
-/*
- * 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.2 FieldInfos writer.
- *
- * @see Lucene42FieldInfosFormat
- * @lucene.experimental
- */
-final class Lucene42FieldInfosWriter extends FieldInfosWriter {
-
- /** Sole constructor. */
- public Lucene42FieldInfosWriter() {
- }
-
- @Override
- public void write(Directory directory, String segmentName, FieldInfos infos, IOContext context) throws IOException {
- final String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene42FieldInfosFormat.EXTENSION);
- IndexOutput output = directory.createOutput(fileName, context);
- boolean success = false;
- try {
- CodecUtil.writeHeader(output, Lucene42FieldInfosFormat.CODEC_NAME, Lucene42FieldInfosFormat.FORMAT_CURRENT);
- output.writeVInt(infos.size());
- for (FieldInfo fi : infos) {
- IndexOptions indexOptions = fi.getIndexOptions();
- byte bits = 0x0;
- if (fi.hasVectors()) bits |= Lucene42FieldInfosFormat.STORE_TERMVECTOR;
- if (fi.omitsNorms()) bits |= Lucene42FieldInfosFormat.OMIT_NORMS;
- if (fi.hasPayloads()) bits |= Lucene42FieldInfosFormat.STORE_PAYLOADS;
- if (fi.isIndexed()) {
- bits |= Lucene42FieldInfosFormat.IS_INDEXED;
- assert indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();
- if (indexOptions == IndexOptions.DOCS_ONLY) {
- bits |= Lucene42FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;
- } else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {
- bits |= Lucene42FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;
- } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) {
- bits |= Lucene42FieldInfosFormat.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.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();
- }
- }
-}
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45Codec.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45Codec.java (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45Codec.java (working copy)
@@ -45,10 +45,12 @@
*
* @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,12 +94,12 @@
}
@Override
- public final FieldInfosFormat fieldInfosFormat() {
+ public FieldInfosFormat fieldInfosFormat() {
return fieldInfosFormat;
}
@Override
- public final SegmentInfoFormat segmentInfoFormat() {
+ public SegmentInfoFormat segmentInfoFormat() {
return infosFormat;
}
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java (working copy)
@@ -0,0 +1,138 @@
+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.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 segmentInfosFormat = new Lucene46SegmentInfoFormat();
+ 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 segmentInfosFormat;
+ }
+
+ @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;
+ }
+}
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46Codec.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java (working copy)
@@ -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;
+}
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java (working copy)
@@ -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 + ")");
+ }
+ }
+}
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java (working copy)
@@ -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();
+ }
+ }
+}
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.java (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.java (working copy)
@@ -0,0 +1,93 @@
+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.CodecUtil;
+import org.apache.lucene.codecs.SegmentInfoFormat;
+import org.apache.lucene.codecs.SegmentInfoReader;
+import org.apache.lucene.codecs.SegmentInfoWriter;
+import org.apache.lucene.index.IndexWriter; // javadocs
+import org.apache.lucene.index.SegmentInfo; // javadocs
+import org.apache.lucene.index.SegmentInfos; // javadocs
+import org.apache.lucene.store.DataOutput; // javadocs
+
+/**
+ * Lucene 4.6 Segment info format.
+ *
+ * Files:
+ *
+ * - .si: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Files
+ *
+ *
+ * Data types:
+ *
+ *
+ * - Header --> {@link CodecUtil#writeHeader CodecHeader}
+ * - SegSize --> {@link DataOutput#writeInt Int32}
+ * - SegVersion --> {@link DataOutput#writeString String}
+ * - Files --> {@link DataOutput#writeStringSet Set<String>}
+ * - Diagnostics --> {@link DataOutput#writeStringStringMap Map<String,String>}
+ * - IsCompoundFile --> {@link DataOutput#writeByte Int8}
+ *
+ *
+ * Field Descriptions:
+ *
+ *
+ * - SegVersion is the code version that created the segment.
+ * - SegSize is the number of documents contained in the segment index.
+ * - IsCompoundFile records whether the segment is written as a compound file or
+ * not. If this is -1, the segment is not a compound file. If it is 1, the segment
+ * is a compound file.
+ * - Checksum contains the CRC32 checksum of all bytes in the segments_N file up
+ * until the checksum. This is used to verify integrity of the file on opening the
+ * index.
+ * - The Diagnostics Map is privately written by {@link IndexWriter}, as a debugging aid,
+ * for each segment it creates. It includes metadata like the current Lucene
+ * version, OS, Java version, why the segment was created (merge, flush,
+ * addIndexes), etc.
+ * - Files is a list of files referred to by this segment.
+ *
+ *
+ *
+ * @see SegmentInfos
+ * @lucene.experimental
+ */
+public class Lucene46SegmentInfoFormat extends SegmentInfoFormat {
+ private final SegmentInfoReader reader = new Lucene46SegmentInfoReader();
+ private final SegmentInfoWriter writer = new Lucene46SegmentInfoWriter();
+
+ /** Sole constructor. */
+ public Lucene46SegmentInfoFormat() {
+ }
+
+ @Override
+ public SegmentInfoReader getSegmentInfoReader() {
+ return reader;
+ }
+
+ @Override
+ public SegmentInfoWriter getSegmentInfoWriter() {
+ return writer;
+ }
+
+ /** File extension used to store {@link SegmentInfo}. */
+ public final static String SI_EXTENSION = "si";
+ static final String CODEC_NAME = "Lucene46SegmentInfo";
+ static final int VERSION_START = 0;
+ static final int VERSION_CURRENT = VERSION_START;
+}
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoReader.java (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoReader.java (working copy)
@@ -0,0 +1,83 @@
+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.Map;
+import java.util.Set;
+
+import org.apache.lucene.codecs.CodecUtil;
+import org.apache.lucene.codecs.SegmentInfoReader;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexFileNames;
+import org.apache.lucene.index.SegmentInfo;
+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 implementation of {@link SegmentInfoReader}.
+ *
+ * @see Lucene46SegmentInfoFormat
+ * @lucene.experimental
+ */
+public class Lucene46SegmentInfoReader extends SegmentInfoReader {
+
+ /** Sole constructor. */
+ public Lucene46SegmentInfoReader() {
+ }
+
+ @Override
+ public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {
+ final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene46SegmentInfoFormat.SI_EXTENSION);
+ final IndexInput input = dir.openInput(fileName, context);
+ boolean success = false;
+ try {
+ CodecUtil.checkHeader(input, Lucene46SegmentInfoFormat.CODEC_NAME,
+ Lucene46SegmentInfoFormat.VERSION_START,
+ Lucene46SegmentInfoFormat.VERSION_CURRENT);
+ final String version = input.readString();
+ final int docCount = input.readInt();
+ if (docCount < 0) {
+ throw new CorruptIndexException("invalid docCount: " + docCount + " (resource=" + input + ")");
+ }
+ final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
+ final Map diagnostics = input.readStringStringMap();
+ final Set files = input.readStringSet();
+
+ 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 + ")");
+ }
+
+ final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics);
+ si.setFiles(files);
+
+ success = true;
+
+ return si;
+
+ } finally {
+ if (!success) {
+ IOUtils.closeWhileHandlingException(input);
+ } else {
+ input.close();
+ }
+ }
+ }
+}
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoReader.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoWriter.java (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoWriter.java (working copy)
@@ -0,0 +1,73 @@
+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.SegmentInfoWriter;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.IndexFileNames;
+import org.apache.lucene.index.SegmentInfo;
+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.0 implementation of {@link SegmentInfoWriter}.
+ *
+ * @see Lucene46SegmentInfoFormat
+ * @lucene.experimental
+ */
+public class Lucene46SegmentInfoWriter extends SegmentInfoWriter {
+
+ /** Sole constructor. */
+ public Lucene46SegmentInfoWriter() {
+ }
+
+ /** Save a single segment's info. */
+ @Override
+ public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
+ final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene46SegmentInfoFormat.SI_EXTENSION);
+ si.addFile(fileName);
+
+ final IndexOutput output = dir.createOutput(fileName, ioContext);
+
+ boolean success = false;
+ try {
+ CodecUtil.writeHeader(output, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_CURRENT);
+ // Write the Lucene version that created this segment, since 3.1
+ output.writeString(si.getVersion());
+ output.writeInt(si.getDocCount());
+
+ output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
+ output.writeStringStringMap(si.getDiagnostics());
+ output.writeStringSet(si.files());
+
+ success = true;
+ } finally {
+ if (!success) {
+ IOUtils.closeWhileHandlingException(output);
+ si.dir.deleteFile(fileName);
+ } else {
+ output.close();
+ }
+ }
+ }
+}
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoWriter.java
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html (revision 0)
+++ lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html (working copy)
@@ -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.lucene46.Lucene46SegmentInfoFormat 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.
+
+
+
Property changes on: lucene/core/src/java/org/apache/lucene/codecs/lucene46/package.html
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/codecs/package.html
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/package.html (revision 1535645)
+++ lucene/core/src/java/org/apache/lucene/codecs/package.html (working copy)
@@ -61,13 +61,13 @@
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)}.