Apache Solr open-source search software
LUCENE-6766: make new Lucene62Codec, with new segment info format that reads/writes the index sort, to support index sorting; remove all usage of SlowCompositeReaderWrapper; also sort ids when merging norms; CheckIndex verifies sort
Mike McCandless8fe78da23c05
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene50/Lucene50Codec.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene50/Lucene50Codec.javaindex 001439ce14d..19d6e3bbe90 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene50/Lucene50Codec.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene50/Lucene50Codec.java@@ -108,7 +108,7 @@ public class Lucene50Codec extends Codec {}@Override- public final SegmentInfoFormat segmentInfoFormat() {+ public SegmentInfoFormat segmentInfoFormat() {return segmentInfosFormat;}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.javanew file mode 100644index 00000000000..9c5453f65b5--- /dev/null+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java@@ -0,0 +1,105 @@+/*+ * 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.+ */+package org.apache.lucene.codecs.lucene50;+++import java.io.IOException;+import java.util.Collections;+import java.util.Map;+import java.util.Set;++import org.apache.lucene.codecs.CodecUtil;+import org.apache.lucene.codecs.SegmentInfoFormat;+import org.apache.lucene.index.CorruptIndexException;+import org.apache.lucene.index.IndexFileNames;+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.ChecksumIndexInput;+import org.apache.lucene.store.DataOutput; // javadocs+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.IndexOutput;+import org.apache.lucene.util.Version;++/**+ * Lucene 5.0 Segment info format.+ * @deprecated Only for reading old 5.0-6.0 segments+ */+@Deprecated+public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {++ /** Sole constructor. */+ public Lucene50SegmentInfoFormat() {+ }++ @Override+ public SegmentInfo read(Directory dir, String segment, byte[] segmentID, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene50SegmentInfoFormat.SI_EXTENSION);+ try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {+ Throwable priorE = null;+ SegmentInfo si = null;+ try {+ int format = CodecUtil.checkIndexHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME,+ Lucene50SegmentInfoFormat.VERSION_START,+ Lucene50SegmentInfoFormat.VERSION_CURRENT,+ segmentID, "");+ final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt());++ final int docCount = input.readInt();+ if (docCount < 0) {+ throw new CorruptIndexException("invalid docCount: " + docCount, input);+ }+ final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;++ final Map<String,String> diagnostics;+ final Set<String> files;+ final Map<String,String> attributes;++ if (format >= VERSION_SAFE_MAPS) {+ diagnostics = input.readMapOfStrings();+ files = input.readSetOfStrings();+ attributes = input.readMapOfStrings();+ } else {+ diagnostics = Collections.unmodifiableMap(input.readStringStringMap());+ files = Collections.unmodifiableSet(input.readStringSet());+ attributes = Collections.unmodifiableMap(input.readStringStringMap());+ }++ si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID, attributes, null);+ si.setFiles(files);+ } catch (Throwable exception) {+ priorE = exception;+ } finally {+ CodecUtil.checkFooter(input, priorE);+ }+ return si;+ }+ }++ @Override+ public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {+ throw new UnsupportedOperationException("this codec can only be used for reading");+ }++ /** File extension used to store {@link SegmentInfo}. */+ public final static String SI_EXTENSION = "si";+ static final String CODEC_NAME = "Lucene50SegmentInfo";+ static final int VERSION_START = 0;+ static final int VERSION_SAFE_MAPS = 1;+ static final int VERSION_CURRENT = VERSION_SAFE_MAPS;+}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60Codec.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene60/Lucene60Codec.javasimilarity index 99%rename from lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60Codec.javarename to lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene60/Lucene60Codec.javaindex c696fbe5f31..7210b3f0dcf 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60Codec.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene60/Lucene60Codec.java@@ -151,7 +151,7 @@ public class Lucene60Codec extends Codec {/** Returns the docvalues format that should be used for writing* new segments of <code>field</code>.*- * The default implementation always returns "Lucene50".+ * The default implementation always returns "Lucene54".* <p>* <b>WARNING:</b> if you subclass, you are responsible for index* backwards compatibility: future version of Lucene are onlydiff --git a/lucene/backward-codecs/src/resources/META-INF/services/org.apache.lucene.codecs.Codec b/lucene/backward-codecs/src/resources/META-INF/services/org.apache.lucene.codecs.Codecindex 7f66de899e7..71aa938e21e 100644--- a/lucene/backward-codecs/src/resources/META-INF/services/org.apache.lucene.codecs.Codec+++ b/lucene/backward-codecs/src/resources/META-INF/services/org.apache.lucene.codecs.Codec@@ -16,3 +16,4 @@org.apache.lucene.codecs.lucene50.Lucene50Codecorg.apache.lucene.codecs.lucene53.Lucene53Codecorg.apache.lucene.codecs.lucene54.Lucene54Codec+org.apache.lucene.codecs.lucene60.Lucene60Codecdiff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/Lucene50RWCodec.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/Lucene50RWCodec.javaindex 359e2ec3d22..8fdeb2041d2 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/Lucene50RWCodec.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/Lucene50RWCodec.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.lucene50;import org.apache.lucene.codecs.NormsFormat;+import org.apache.lucene.codecs.SegmentInfoFormat;/*** Codec for testing 5.0 index format@@ -26,9 +27,15 @@ import org.apache.lucene.codecs.NormsFormat;@Deprecatedfinal class Lucene50RWCodec extends Lucene50Codec {private final NormsFormat normsFormat = new Lucene50RWNormsFormat();+ private final SegmentInfoFormat segmentInfoFormat = new Lucene50RWSegmentInfoFormat();@Overridepublic NormsFormat normsFormat() {return normsFormat;}++ @Override+ public SegmentInfoFormat segmentInfoFormat() {+ return segmentInfoFormat;+ }}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/Lucene50RWSegmentInfoFormat.javasimilarity index 77%rename from lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.javarename to lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/Lucene50RWSegmentInfoFormat.javaindex 9786ec11aa3..d457243f67b 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene50/Lucene50RWSegmentInfoFormat.java@@ -37,43 +37,14 @@ import org.apache.lucene.store.IndexOutput;import org.apache.lucene.util.Version;/**- * Lucene 5.0 Segment info format.- * <p>- * Files:- * <ul>- * <li><tt>.si</tt>: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Files, Attributes, Footer- * </ul>- * Data types:- * <ul>- * <li>Header --> {@link CodecUtil#writeIndexHeader IndexHeader}</li>- * <li>SegSize --> {@link DataOutput#writeInt Int32}</li>- * <li>SegVersion --> {@link DataOutput#writeString String}</li>- * <li>Files --> {@link DataOutput#writeSetOfStrings Set<String>}</li>- * <li>Diagnostics,Attributes --> {@link DataOutput#writeMapOfStrings Map<String,String>}</li>- * <li>IsCompoundFile --> {@link DataOutput#writeByte Int8}</li>- * <li>Footer --> {@link CodecUtil#writeFooter CodecFooter}</li>- * </ul>- * Field Descriptions:- * <ul>- * <li>SegVersion is the code version that created the segment.</li>- * <li>SegSize is the number of documents contained in the segment index.</li>- * <li>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.</li>- * <li>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.</li>- * <li>Files is a list of files referred to by this segment.</li>- * </ul>- *- * @see SegmentInfos- * @lucene.experimental+ * Read-write version of 5.0 SegmentInfoFormat for testing+ * @deprecated for test purposes only*/-public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {+@Deprecated+public class Lucene50RWSegmentInfoFormat extends Lucene50SegmentInfoFormat {/** Sole constructor. */- public Lucene50SegmentInfoFormat() {+ public Lucene50RWSegmentInfoFormat() {}@Overridediff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.javaindex 74486d6c38c..df8a1b49404 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java@@ -29,7 +29,7 @@ import org.apache.lucene.benchmark.byTask.PerfRunData;import org.apache.lucene.benchmark.byTask.utils.Config;import org.apache.lucene.codecs.Codec;import org.apache.lucene.codecs.PostingsFormat;-import org.apache.lucene.codecs.lucene60.Lucene60Codec;+import org.apache.lucene.codecs.lucene62.Lucene62Codec;import org.apache.lucene.index.ConcurrentMergeScheduler;import org.apache.lucene.index.IndexCommit;import org.apache.lucene.index.IndexDeletionPolicy;@@ -139,7 +139,7 @@ public class CreateIndexTask extends PerfTask {if (defaultCodec == null && postingsFormat != null) {try {final PostingsFormat postingsFormatChosen = PostingsFormat.forName(postingsFormat);- iwConf.setCodec(new Lucene60Codec() {+ iwConf.setCodec(new Lucene62Codec() {@Overridepublic PostingsFormat getPostingsFormatForField(String field) {return postingsFormatChosen;diff --git a/lucene/classification/build.xml b/lucene/classification/build.xmlindex 3ddb9bd26e6..704cae8973d 100644--- a/lucene/classification/build.xml+++ b/lucene/classification/build.xml@@ -28,7 +28,6 @@<path refid="base.classpath"/><pathelement path="${queries.jar}"/><pathelement path="${grouping.jar}"/>- <pathelement path="${misc.jar}"/></path><path id="test.classpath">@@ -37,17 +36,16 @@<path refid="test.base.classpath"/></path>- <target name="compile-core" depends="jar-misc,jar-grouping,jar-queries,jar-analyzers-common,common.compile-core" />+ <target name="compile-core" depends="jar-grouping,jar-queries,jar-analyzers-common,common.compile-core" /><target name="jar-core" depends="common.jar-core" />- <target name="javadocs" depends="javadocs-misc,javadocs-grouping,javadocs-misc,compile-core,check-javadocs-uptodate"+ <target name="javadocs" depends="javadocs-grouping,compile-core,check-javadocs-uptodate"unless="javadocs-uptodate-${name}"><invoke-module-javadoc><links><link href="../queries"/><link href="../grouping"/>- <link href="../misc"/></links></invoke-module-javadoc></target>diff --git a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.javaindex fce786bf1e9..c1c8ad19ee6 100644--- a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java+++ b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java@@ -29,6 +29,7 @@ import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.IndexableField;import org.apache.lucene.index.LeafReader;+import org.apache.lucene.index.SortedDocValues;import org.apache.lucene.index.Terms;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.MatchAllDocsQuery;@@ -38,7 +39,6 @@ import org.apache.lucene.search.grouping.GroupDocs;import org.apache.lucene.search.grouping.GroupingSearch;import org.apache.lucene.search.grouping.TopGroups;import org.apache.lucene.store.Directory;-import org.apache.lucene.uninverting.UninvertingReader;/*** Utility class for creating training / test / cross validation indexes from the original index.@@ -68,7 +68,7 @@ public class DatasetSplitter {* @param crossValidationIndex a {@link Directory} used to write the cross validation index* @param analyzer {@link Analyzer} used to create the new docs* @param termVectors {@code true} if term vectors should be kept- * @param classFieldName names of the field used as the label for classification+ * @param classFieldName name of the field used as the label for classification; this must be indexed with sorted doc values* @param fieldNames names of fields that need to be put in the new indexes or <code>null</code> if all should be used* @throws IOException if any writing operation fails on any of the indexes*/@@ -80,30 +80,23 @@ public class DatasetSplitter {IndexWriter cvWriter = new IndexWriter(crossValidationIndex, new IndexWriterConfig(analyzer));IndexWriter trainingWriter = new IndexWriter(trainingIndex, new IndexWriterConfig(analyzer));- // try to get the exact no. of existing classes- Terms terms = originalIndex.terms(classFieldName);- long noOfClasses = -1;- if (terms != null) {- noOfClasses = terms.size();-- }- if (noOfClasses == -1) {- noOfClasses = 10000; // fallback+ // get the exact no. of existing classes+ SortedDocValues classValues = originalIndex.getSortedDocValues(classFieldName);+ if (classValues == null) {+ throw new IllegalStateException("the classFieldName \"" + classFieldName + "\" must index sorted doc values");}- HashMap<String, UninvertingReader.Type> mapping = new HashMap<>();- mapping.put(classFieldName, UninvertingReader.Type.SORTED);- UninvertingReader uninvertingReader = new UninvertingReader(originalIndex, mapping);+ int noOfClasses = classValues.getValueCount();try {- IndexSearcher indexSearcher = new IndexSearcher(uninvertingReader);+ IndexSearcher indexSearcher = new IndexSearcher(originalIndex);GroupingSearch gs = new GroupingSearch(classFieldName);gs.setGroupSort(Sort.INDEXORDER);gs.setSortWithinGroup(Sort.INDEXORDER);gs.setAllGroups(true);gs.setGroupDocsLimit(originalIndex.maxDoc());- TopGroups<Object> topGroups = gs.search(indexSearcher, new MatchAllDocsQuery(), 0, (int) noOfClasses);+ TopGroups<Object> topGroups = gs.search(indexSearcher, new MatchAllDocsQuery(), 0, noOfClasses);// set the type to be indexed, stored, with term vectorsFieldType ft = new FieldType(TextField.TYPE_STORED);@@ -156,7 +149,7 @@ public class DatasetSplitter {testWriter.close();cvWriter.close();trainingWriter.close();- uninvertingReader.close();+ originalIndex.close();}}diff --git a/lucene/classification/src/test/org/apache/lucene/classification/utils/DataSplitterTest.java b/lucene/classification/src/test/org/apache/lucene/classification/utils/DataSplitterTest.javaindex 0b6f077cdfd..fdd4b0bb4a8 100644--- a/lucene/classification/src/test/org/apache/lucene/classification/utils/DataSplitterTest.java+++ b/lucene/classification/src/test/org/apache/lucene/classification/utils/DataSplitterTest.java@@ -70,7 +70,9 @@ public class DataSplitterTest extends LuceneTestCase {doc = new Document();doc.add(new Field(idFieldName, "id" + Integer.toString(i), ft));doc.add(new Field(textFieldName, TestUtil.randomUnicodeString(rnd, 1024), ft));- doc.add(new Field(classFieldName, Integer.toString(rnd.nextInt(10)), ft));+ String className = Integer.toString(rnd.nextInt(10));+ doc.add(new Field(classFieldName, className, ft));+ doc.add(new SortedDocValuesField(classFieldName, new BytesRef(className)));indexWriter.addDocument(doc);}@@ -89,13 +91,11 @@ public class DataSplitterTest extends LuceneTestCase {super.tearDown();}-@Testpublic void testSplitOnAllFields() throws Exception {assertSplit(originalIndex, 0.1, 0.1);}-@Testpublic void testSplitOnSomeFields() throws Exception {assertSplit(originalIndex, 0.2, 0.35, idFieldName, textFieldName);diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.javaindex 594fccf2472..bf9d3ded573 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java@@ -216,6 +216,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {break;}break;+ // nocommit need the restdefault:throw new AssertionError();}@@ -337,6 +338,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {case INT:sortType = "int";break;+ // nocommit the rest:default:throw new IllegalStateException("Unexpected sort type: " + sortField.getType());}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/Codec.javaindex 5d704ca017d..442445c2237 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/Codec.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/Codec.java@@ -57,7 +57,7 @@ public abstract class Codec implements NamedSPILoader.NamedSPI {}// TODO: should we use this, or maybe a system property is better?- static Codec defaultCodec = LOADER.lookup("Lucene60");+ static Codec defaultCodec = LOADER.lookup("Lucene62");}private final String name;diff --git a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.javaindex 52bf9b2f82d..79cc42227d4 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java@@ -316,16 +316,14 @@ public abstract class DocValuesConsumer implements Closeable {}private boolean setNext() {- while (true) {- NumericDocValuesSub sub = docIDMerger.next();- if (sub == null) {- return false;- }- nextIsSet = true;- nextValue = sub.values.get(sub.docID);- nextHasValue = nextValue != 0 || sub.docsWithField.get(sub.docID);- return true;+ NumericDocValuesSub sub = docIDMerger.next();+ if (sub == null) {+ return false;}+ nextIsSet = true;+ nextValue = sub.values.get(sub.docID);+ nextHasValue = nextValue != 0 || sub.docsWithField.get(sub.docID);+ return true;}};}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/NormsConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/NormsConsumer.javaindex b771aabf43a..76f8be727f5 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/NormsConsumer.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/NormsConsumer.java@@ -16,7 +16,6 @@*/package org.apache.lucene.codecs;-import java.io.Closeable;import java.io.IOException;import java.util.ArrayList;@@ -24,6 +23,7 @@ import java.util.Iterator;import java.util.List;import java.util.NoSuchElementException;+import org.apache.lucene.index.DocIDMerger;import org.apache.lucene.index.DocValues;import org.apache.lucene.index.FieldInfo;import org.apache.lucene.index.MergeState;@@ -31,6 +31,8 @@ import org.apache.lucene.index.NumericDocValues;import org.apache.lucene.index.SegmentWriteState;import org.apache.lucene.util.Bits;+import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;+/*** Abstract API that consumes normalization values.* Concrete implementations of this@@ -98,6 +100,30 @@ public abstract class NormsConsumer implements Closeable {}}+ /** Tracks state of one numeric sub-reader that we are merging */+ private static class NumericDocValuesSub extends DocIDMerger.Sub {++ private final NumericDocValues values;+ private int docID = -1;+ private final int maxDoc;++ public NumericDocValuesSub(MergeState.DocMap docMap, Bits liveDocs, NumericDocValues values, int maxDoc) {+ super(docMap, liveDocs);+ this.values = values;+ this.maxDoc = maxDoc;+ }++ @Override+ public int nextDoc() {+ docID++;+ if (docID == maxDoc) {+ return NO_MORE_DOCS;+ } else {+ return docID;+ }+ }+ }+/*** Merges the norms from <code>toMerge</code>.* <p>@@ -111,13 +137,18 @@ public abstract class NormsConsumer implements Closeable {new Iterable<Number>() {@Overridepublic Iterator<Number> iterator() {++ // We must make a new DocIDMerger for each iterator:+ List<NumericDocValuesSub> subs = new ArrayList<>();+ assert mergeState.docMaps.length == toMerge.size();+ for(int i=0;i<toMerge.size();i++) {+ subs.add(new NumericDocValuesSub(mergeState.docMaps[i], mergeState.liveDocs[i], toMerge.get(i), mergeState.maxDocs[i]));+ }++ final DocIDMerger<NumericDocValuesSub> docIDMerger = new DocIDMerger<>(subs, mergeState.segmentInfo.getIndexSort() != null);+return new Iterator<Number>() {- int readerUpto = -1;- int docIDUpto;long nextValue;- int maxDoc;- NumericDocValues currentValues;- Bits currentLiveDocs;boolean nextIsSet;@Override@@ -141,31 +172,13 @@ public abstract class NormsConsumer implements Closeable {}private boolean setNext() {- while (true) {- if (readerUpto == toMerge.size()) {- return false;- }-- if (currentValues == null || docIDUpto == maxDoc) {- readerUpto++;- if (readerUpto < toMerge.size()) {- currentValues = toMerge.get(readerUpto);- currentLiveDocs = mergeState.liveDocs[readerUpto];- maxDoc = mergeState.maxDocs[readerUpto];- }- docIDUpto = 0;- continue;- }-- if (currentLiveDocs == null || currentLiveDocs.get(docIDUpto)) {- nextIsSet = true;- nextValue = currentValues.get(docIDUpto);- docIDUpto++;- return true;- }-- docIDUpto++;+ NumericDocValuesSub sub = docIDMerger.next();+ if (sub == null) {+ return false;}+ nextIsSet = true;+ nextValue = sub.values.get(sub.docID);+ return true;}};}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsWriter.javaindex 79dfb27ad53..d5bf4ad8e88 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsWriter.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsWriter.java@@ -486,6 +486,12 @@ public final class CompressingStoredFieldsWriter extends StoredFieldsWriter {@Overridepublic int merge(MergeState mergeState) throws IOException {+ if (mergeState.segmentInfo.getIndexSort() != null) {+ // TODO: can we gain back some optos even if index is sorted? E.g. if sort results in large chunks of contiguous docs from one sub+ // being copied over...?+ return super.merge(mergeState);+ }+int docCount = 0;int numReaders = mergeState.maxDocs.length;diff --git a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsWriter.javaindex 07f27117f0d..9f8f44ef36d 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsWriter.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingTermVectorsWriter.java@@ -730,6 +730,11 @@ public final class CompressingTermVectorsWriter extends TermVectorsWriter {@Overridepublic int merge(MergeState mergeState) throws IOException {+ if (mergeState.segmentInfo.getIndexSort() != null) {+ // TODO: can we gain back some optos even if index is sorted? E.g. if sort results in large chunks of contiguous docs from one sub+ // being copied over...?+ return super.merge(mergeState);+ }int docCount = 0;int numReaders = mergeState.maxDocs.length;diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene54/package-info.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene54/package-info.javaindex ebae8491bc2..5dec06bf16a 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene54/package-info.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene54/package-info.java@@ -135,7 +135,7 @@* <p>Each segment index maintains the following:</p>* <ul>* <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50SegmentInfoFormat Segment info}.+ * {@link org.apache.lucene.codecs.lucene62.Lucene62SegmentInfoFormat Segment info}.* This contains metadata about a segment, such as the number of documents,* what files it uses,* </li>@@ -235,7 +235,7 @@* file.</td>* </tr>* <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50SegmentInfoFormat Segment Info}</td>+ * <td>{@link org.apache.lucene.codecs.lucene62.Lucene62SegmentInfoFormat Segment Info}</td>* <td>.si</td>* <td>Stores metadata about a segment</td>* </tr>diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointsWriter.javaindex f6c73bdcc02..63308c422b3 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointsWriter.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60PointsWriter.java@@ -123,6 +123,13 @@ public class Lucene60PointsWriter extends PointsWriter implements Closeable {@Overridepublic void merge(MergeState mergeState) throws IOException {+ if (mergeState.segmentInfo.getIndexSort() != null) {+ // TODO: can we gain back some optos even if index is sorted? E.g. if sort results in large chunks of contiguous docs from one sub+ // being copied over...?+ super.merge(mergeState);+ return;+ }+for(PointsReader reader : mergeState.pointsReaders) {if (reader instanceof Lucene60PointsReader == false) {// We can only bulk merge when all to-be-merged segments use our format:diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/package-info.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/package-info.javaindex 03a17ba2e38..8968a6d624c 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/package-info.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/package-info.java@@ -16,400 +16,7 @@*//**- * Lucene 6.0 file format.- *- * <h1>Apache Lucene - Index File Formats</h1>- * <div>- * <ul>- * <li><a href="#Introduction">Introduction</a></li>- * <li><a href="#Definitions">Definitions</a>- * <ul>- * <li><a href="#Inverted_Indexing">Inverted Indexing</a></li>- * <li><a href="#Types_of_Fields">Types of Fields</a></li>- * <li><a href="#Segments">Segments</a></li>- * <li><a href="#Document_Numbers">Document Numbers</a></li>- * </ul>- * </li>- * <li><a href="#Overview">Index Structure Overview</a></li>- * <li><a href="#File_Naming">File Naming</a></li>- * <li><a href="#file-names">Summary of File Extensions</a>- * <ul>- * <li><a href="#Lock_File">Lock File</a></li>- * <li><a href="#History">History</a></li>- * <li><a href="#Limitations">Limitations</a></li>- * </ul>- * </li>- * </ul>- * </div>- * <a name="Introduction"></a>- * <h2>Introduction</h2>- * <div>- * <p>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- * <code>docs/</code> that was distributed with- * the version you are using.</p>- * <p>Apache Lucene is written in Java, but several efforts are underway to write- * <a href="http://wiki.apache.org/lucene-java/LuceneImplementations">versions of- * Lucene in other programming languages</a>. 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.</p>- * <p>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.</p>- * </div>- * <a name="Definitions"></a>- * <h2>Definitions</h2>- * <div>- * <p>The fundamental concepts in Lucene are index, document, field and term.</p>- * <p>An index contains a sequence of documents.</p>- * <ul>- * <li>A document is a sequence of fields.</li>- * <li>A field is a named sequence of terms.</li>- * <li>A term is a sequence of bytes.</li>- * </ul>- * <p>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.</p>- * <a name="Inverted_Indexing"></a>- * <h3>Inverted Indexing</h3>- * <p>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- * <i>inverted index.</i> 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.</p>- * <a name="Types_of_Fields"></a>- * <h3>Types of Fields</h3>- * <p>In Lucene, fields may be <i>stored</i>, in which case their text is stored- * in the index literally, in a non-inverted manner. Fields that are inverted are- * called <i>indexed</i>. A field may be both stored and indexed.</p>- * <p>The text of a field may be <i>tokenized</i> 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.</p>- * <p>See the {@link org.apache.lucene.document.Field Field}- * java docs for more information on Fields.</p>- * <a name="Segments"></a>- * <h3>Segments</h3>- * <p>Lucene indexes may be composed of multiple sub-indexes, or <i>segments</i>.- * Each segment is a fully independent index, which could be searched separately.- * Indexes evolve by:</p>- * <ol>- * <li>Creating new segments for newly added documents.</li>- * <li>Merging existing segments.</li>- * </ol>- * <p>Searches may involve multiple segments and/or multiple indexes, each index- * potentially composed of a set of segments.</p>- * <a name="Document_Numbers"></a>- * <h3>Document Numbers</h3>- * <p>Internally, Lucene refers to documents by an integer <i>document number</i>.- * The first document added to an index is numbered zero, and each subsequent- * document added gets a number one greater than the previous.</p>- * <p>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:</p>- * <ul>- * <li>- * <p>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 <i>base</i> 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.</p>- * </li>- * <li>- * <p>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.</p>- * </li>- * </ul>- * </div>- * <a name="Overview"></a>- * <h2>Index Structure Overview</h2>- * <div>- * <p>Each segment index maintains the following:</p>- * <ul>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50SegmentInfoFormat Segment info}.- * This contains metadata about a segment, such as the number of documents,- * what files it uses,- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50FieldInfosFormat Field names}.- * This contains the set of field names used in the index.- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat 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.- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat 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.- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat 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)- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat 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.- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene53.Lucene53NormsFormat Normalization factors}.- * For each field in each document, a value is stored- * that is multiplied into the score for hits on that field.- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50TermVectorsFormat 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- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene54.Lucene54DocValuesFormat 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.- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene50.Lucene50LiveDocsFormat Live documents}.- * An optional file indicating which documents are live.- * </li>- * <li>- * {@link org.apache.lucene.codecs.lucene60.Lucene60PointsFormat Point values}.- * Optional pair of files, recording dimensionally indexed fields, to enable fast- * numeric range filtering and large numeric values like BigInteger and BigDecimal (1D)- * and geographic shape intersection (2D, 3D).- * </li>- * </ul>- * <p>Details on each of these are provided in their linked pages.</p>- * </div>- * <a name="File_Naming"></a>- * <h2>File Naming</h2>- * <div>- * <p>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)</p>- * <p>Typically, all segments in an index are stored in a single directory,- * although this is not required.</p>- * <p>As of version 2.1 (lock-less commits), file names are never re-used.- * 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.</p>- * </div>- * <a name="file-names"></a>- * <h2>Summary of File Extensions</h2>- * <div>- * <p>The following table summarizes the names and extensions of the files in- * Lucene:</p>- * <table cellspacing="1" cellpadding="4" summary="lucene filenames by extension">- * <tr>- * <th>Name</th>- * <th>Extension</th>- * <th>Brief Description</th>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.index.SegmentInfos Segments File}</td>- * <td>segments_N</td>- * <td>Stores information about a commit point</td>- * </tr>- * <tr>- * <td><a href="#Lock_File">Lock File</a></td>- * <td>write.lock</td>- * <td>The Write lock prevents multiple IndexWriters from writing to the same- * file.</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50SegmentInfoFormat Segment Info}</td>- * <td>.si</td>- * <td>Stores metadata about a segment</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50CompoundFormat Compound File}</td>- * <td>.cfs, .cfe</td>- * <td>An optional "virtual" file consisting of all the other index files for- * systems that frequently run out of file handles.</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50FieldInfosFormat Fields}</td>- * <td>.fnm</td>- * <td>Stores information about the fields</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat Field Index}</td>- * <td>.fdx</td>- * <td>Contains pointers to field data</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat Field Data}</td>- * <td>.fdt</td>- * <td>The stored fields for documents</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat Term Dictionary}</td>- * <td>.tim</td>- * <td>The term dictionary, stores term info</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat Term Index}</td>- * <td>.tip</td>- * <td>The index into the Term Dictionary</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat Frequencies}</td>- * <td>.doc</td>- * <td>Contains the list of docs which contain each term along with frequency</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat Positions}</td>- * <td>.pos</td>- * <td>Stores position information about where a term occurs in the index</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat Payloads}</td>- * <td>.pay</td>- * <td>Stores additional per-position metadata information such as character offsets and user payloads</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene53.Lucene53NormsFormat Norms}</td>- * <td>.nvd, .nvm</td>- * <td>Encodes length and boost factors for docs and fields</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene54.Lucene54DocValuesFormat Per-Document Values}</td>- * <td>.dvd, .dvm</td>- * <td>Encodes additional scoring factors or other per-document information.</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50TermVectorsFormat Term Vector Index}</td>- * <td>.tvx</td>- * <td>Stores offset into the document data file</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50TermVectorsFormat Term Vector Documents}</td>- * <td>.tvd</td>- * <td>Contains information about each document that has term vectors</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50TermVectorsFormat Term Vector Fields}</td>- * <td>.tvf</td>- * <td>The field level info about term vectors</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene50.Lucene50LiveDocsFormat Live Documents}</td>- * <td>.liv</td>- * <td>Info about what files are live</td>- * </tr>- * <tr>- * <td>{@link org.apache.lucene.codecs.lucene60.Lucene60PointsFormat Point values}</td>- * <td>.dii, .dim</td>- * <td>Holds indexed points, if any</td>- * </tr>- * </table>- * </div>- * <a name="Lock_File"></a>- * <h2>Lock File</h2>- * 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.- * <a name="History"></a>- * <h2>History</h2>- * <p>Compatibility notes are provided in this document, describing how file- * formats have changed from prior versions:</p>- * <ul>- * <li>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.</li>- * <li>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).</li>- * <li>In version 2.4, Strings are now written as true UTF-8 byte sequence, not- * Java's modified UTF-8. See <a href="http://issues.apache.org/jira/browse/LUCENE-510">- * LUCENE-510</a> for details.</li>- * <li>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 <a href="http://issues.apache.org/jira/browse/LUCENE-1382">- * LUCENE-1382</a> 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- * <a href="http://issues.apache.org/jira/browse/LUCENE-1654">LUCENE-1654</a> for details.</li>- * <li>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 <a href="http://issues.apache.org/jira/browse/LUCENE-1960">LUCENE-1960</a>- * for details.</li>- * <li>In version 3.1, segments records the code version that created them. See- * <a href="http://issues.apache.org/jira/browse/LUCENE-2720">LUCENE-2720</a> for details.- * Additionally segments track explicitly whether or not they have term vectors.- * See <a href="http://issues.apache.org/jira/browse/LUCENE-2811">LUCENE-2811</a>- * for details.</li>- * <li>In version 3.2, numeric fields are written as natively to stored fields- * file, previously they were stored in text format only.</li>- * <li>In version 3.4, fields can omit position data while still indexing term- * frequencies.</li>- * <li>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.</li>- * <li>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. </li>- * <li>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.</li>- * <li>In version 4.5, DocValues were extended to explicitly represent missing values.</li>- * <li>In version 4.6, FieldInfos were extended to support per-field DocValues generation, to- * allow updating NumericDocValues fields.</li>- * <li>In version 4.8, checksum footers were added to the end of each index file- * for improved data integrity. Specifically, the last 8 bytes of every index file- * contain the zlib-crc32 checksum of the file.</li>- * <li>In version 4.9, DocValues has a new multi-valued numeric type (SortedNumeric)- * that is suitable for faceting/sorting/analytics.- * <li>In version 5.4, DocValues have been improved to store more information on disk:- * addresses for binary fields and ord indexes for multi-valued fields.- * <li>In version 6.0, Points were added, for multi-dimensional range/distance search.- * </li>- * </ul>- * <a name="Limitations"></a>- * <h2>Limitations</h2>- * <div>- * <p>Lucene uses a Java <code>int</code> to refer to- * document numbers, and the index file format uses an <code>Int32</code>- * 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 <code>UInt64</code> values, or- * better yet, {@link org.apache.lucene.store.DataOutput#writeVInt VInt} values which have no limit.</p>- * </div>+ * Components from the Lucene 6.0 index format. See {@link org.apache.lucene.codecs.lucene62}+ * for an overview of the index format.*/package org.apache.lucene.codecs.lucene60;diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62Codec.javanew file mode 100644index 00000000000..aa0adaed8cd--- /dev/null+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62Codec.java@@ -0,0 +1,178 @@+/*+ * 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.+ */+package org.apache.lucene.codecs.lucene62;++import java.util.Objects;++import org.apache.lucene.codecs.Codec;+import org.apache.lucene.codecs.CompoundFormat;+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.PointsFormat;+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.lucene50.Lucene50CompoundFormat;+import org.apache.lucene.codecs.lucene50.Lucene50LiveDocsFormat;+import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode;+import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat;+import org.apache.lucene.codecs.lucene50.Lucene50TermVectorsFormat;+import org.apache.lucene.codecs.lucene53.Lucene53NormsFormat;+import org.apache.lucene.codecs.lucene60.Lucene60FieldInfosFormat;+import org.apache.lucene.codecs.lucene60.Lucene60PointsFormat;+import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;+import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;++// nocommit if somehow this does NOT land in 6.2, rename all this!!++/**+ * Implements the Lucene 6.2 index format, with configurable per-field postings+ * and docvalues formats.+ * <p>+ * If you want to reuse functionality of this codec in another codec, extend+ * {@link FilterCodec}.+ *+ * @see org.apache.lucene.codecs.lucene60 package documentation for file format details.+ *+ * @lucene.experimental+ */+public class Lucene62Codec extends Codec {+ private final TermVectorsFormat vectorsFormat = new Lucene50TermVectorsFormat();+ private final FieldInfosFormat fieldInfosFormat = new Lucene60FieldInfosFormat();+ private final SegmentInfoFormat segmentInfosFormat = new Lucene62SegmentInfoFormat();+ private final LiveDocsFormat liveDocsFormat = new Lucene50LiveDocsFormat();+ private final CompoundFormat compoundFormat = new Lucene50CompoundFormat();++ private final PostingsFormat postingsFormat = new PerFieldPostingsFormat() {+ @Override+ public PostingsFormat getPostingsFormatForField(String field) {+ return Lucene62Codec.this.getPostingsFormatForField(field);+ }+ };++ private final DocValuesFormat docValuesFormat = new PerFieldDocValuesFormat() {+ @Override+ public DocValuesFormat getDocValuesFormatForField(String field) {+ return Lucene62Codec.this.getDocValuesFormatForField(field);+ }+ };++ private final StoredFieldsFormat storedFieldsFormat;++ /**+ * Instantiates a new codec.+ */+ public Lucene62Codec() {+ this(Mode.BEST_SPEED);+ }++ /**+ * Instantiates a new codec, specifying the stored fields compression+ * mode to use.+ * @param mode stored fields compression mode to use for newly+ * flushed/merged segments.+ */+ public Lucene62Codec(Mode mode) {+ super("Lucene62");+ this.storedFieldsFormat = new Lucene50StoredFieldsFormat(Objects.requireNonNull(mode));+ }++ @Override+ public final StoredFieldsFormat storedFieldsFormat() {+ return storedFieldsFormat;+ }++ @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;+ }++ @Override+ public final CompoundFormat compoundFormat() {+ return compoundFormat;+ }++ @Override+ public final PointsFormat pointsFormat() {+ return new Lucene60PointsFormat();+ }++ /** Returns the postings format that should be used for writing+ * new segments of <code>field</code>.+ *+ * The default implementation always returns "Lucene50".+ * <p>+ * <b>WARNING:</b> if you subclass, you are responsible for index+ * backwards compatibility: future version of Lucene are only+ * guaranteed to be able to read the default implementation.+ */+ public PostingsFormat getPostingsFormatForField(String field) {+ return defaultFormat;+ }++ /** Returns the docvalues format that should be used for writing+ * new segments of <code>field</code>.+ *+ * The default implementation always returns "Lucene54".+ * <p>+ * <b>WARNING:</b> if you subclass, you are responsible for index+ * backwards compatibility: future version of Lucene are only+ * guaranteed to be able to read the default implementation.+ */+ public DocValuesFormat getDocValuesFormatForField(String field) {+ return defaultDVFormat;+ }++ @Override+ public final DocValuesFormat docValuesFormat() {+ return docValuesFormat;+ }++ private final PostingsFormat defaultFormat = PostingsFormat.forName("Lucene50");+ private final DocValuesFormat defaultDVFormat = DocValuesFormat.forName("Lucene54");++ private final NormsFormat normsFormat = new Lucene53NormsFormat();++ @Override+ public final NormsFormat normsFormat() {+ return normsFormat;+ }+}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62SegmentInfoFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62SegmentInfoFormat.javanew file mode 100644index 00000000000..53d273474a8--- /dev/null+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62SegmentInfoFormat.java@@ -0,0 +1,289 @@+/*+ * 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.+ */+package org.apache.lucene.codecs.lucene62;++import java.io.IOException;+import java.util.Collections;+import java.util.Map;+import java.util.Set;++import org.apache.lucene.codecs.CodecUtil;+import org.apache.lucene.codecs.SegmentInfoFormat;+import org.apache.lucene.index.CorruptIndexException;+import org.apache.lucene.index.IndexFileNames;+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.search.Sort;+import org.apache.lucene.search.SortField;+import org.apache.lucene.store.ChecksumIndexInput;+import org.apache.lucene.store.DataOutput; // javadocs+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.IndexOutput;+import org.apache.lucene.util.Version;++// nocommit fixup javadocs here:++/**+ * Lucene 6.2 Segment info format.+ * <p>+ * Files:+ * <ul>+ * <li><tt>.si</tt>: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Files, Attributes, IndexSort, Footer+ * </ul>+ * Data types:+ * <ul>+ * <li>Header --> {@link CodecUtil#writeIndexHeader IndexHeader}</li>+ * <li>SegSize --> {@link DataOutput#writeInt Int32}</li>+ * <li>SegVersion --> {@link DataOutput#writeString String}</li>+ * <li>Files --> {@link DataOutput#writeSetOfStrings Set<String>}</li>+ * <li>Diagnostics,Attributes --> {@link DataOutput#writeMapOfStrings Map<String,String>}</li>+ * <li>IsCompoundFile --> {@link DataOutput#writeByte Int8}</li>+ * <li>IndexSort --> {@link DataOutput#writeInt Int32} count, followed by {@code count} SortField</li>+ * <li>Footer --> {@link CodecUtil#writeFooter CodecFooter}</li>+ * </ul>+ * Field Descriptions:+ * <ul>+ * <li>SegVersion is the code version that created the segment.</li>+ * <li>SegSize is the number of documents contained in the segment index.</li>+ * <li>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.</li>+ * <li>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.</li>+ * <li>Files is a list of files referred to by this segment.</li>+ * </ul>+ *+ * @see SegmentInfos+ * @lucene.experimental+ */+public class Lucene62SegmentInfoFormat extends SegmentInfoFormat {++ /** Sole constructor. */+ public Lucene62SegmentInfoFormat() {+ }++ @Override+ public SegmentInfo read(Directory dir, String segment, byte[] segmentID, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene62SegmentInfoFormat.SI_EXTENSION);+ try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {+ Throwable priorE = null;+ SegmentInfo si = null;+ try {+ int format = CodecUtil.checkIndexHeader(input, Lucene62SegmentInfoFormat.CODEC_NAME,+ Lucene62SegmentInfoFormat.VERSION_START,+ Lucene62SegmentInfoFormat.VERSION_CURRENT,+ segmentID, "");+ final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt());++ final int docCount = input.readInt();+ if (docCount < 0) {+ throw new CorruptIndexException("invalid docCount: " + docCount, input);+ }+ final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;++ final Map<String,String> diagnostics = input.readMapOfStrings();+ final Set<String> files = input.readSetOfStrings();+ final Map<String,String> attributes = input.readMapOfStrings();++ int numSortFields = input.readVInt();+ Sort indexSort;+ if (numSortFields > 0) {+ SortField[] sortFields = new SortField[numSortFields];+ for(int i=0;i<numSortFields;i++) {+ String fieldName = input.readString();+ int sortTypeID = input.readVInt();+ SortField.Type sortType;+ switch(sortTypeID) {+ case 0:+ sortType = SortField.Type.STRING;+ break;+ case 1:+ sortType = SortField.Type.LONG;+ break;+ case 2:+ sortType = SortField.Type.INT;+ break;+ default:+ throw new CorruptIndexException("invalid index sort field type ID: " + sortTypeID, input);+ }+ byte b = input.readByte();+ boolean reverse;+ if (b == 0) {+ reverse = true;+ } else if (b == 1) {+ reverse = false;+ } else {+ throw new CorruptIndexException("invalid index sort reverse: " + b, input);+ }++ sortFields[i] = new SortField(fieldName, sortType, reverse);++ Object missingValue;+ b = input.readByte();+ if (b == 0) {+ missingValue = null;+ } else {+ switch(sortType) {+ case STRING:+ if (b == 1) {+ missingValue = SortField.STRING_LAST;+ } else if (b == 2) {+ missingValue = SortField.STRING_FIRST;+ } else {+ throw new CorruptIndexException("invalid missing value flag: " + b, input);+ }+ break;+ case LONG:+ if (b != 1) {+ throw new CorruptIndexException("invalid missing value flag: " + b, input);+ }+ missingValue = input.readLong();+ break;+ case INT:+ if (b != 1) {+ throw new CorruptIndexException("invalid missing value flag: " + b, input);+ }+ missingValue = input.readInt();+ break;+ default:+ throw new AssertionError("unhandled sortType=" + sortType);+ }+ }+ if (missingValue != null) {+ sortFields[i].setMissingValue(missingValue);+ }+ }+ indexSort = new Sort(sortFields);+ } else if (numSortFields < 0) {+ throw new CorruptIndexException("invalid index sort field count: " + numSortFields, input);+ } else {+ indexSort = null;+ }++ si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID, attributes, indexSort);+ si.setFiles(files);+ } catch (Throwable exception) {+ priorE = exception;+ } finally {+ CodecUtil.checkFooter(input, priorE);+ }+ return si;+ }+ }++ @Override+ public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene62SegmentInfoFormat.SI_EXTENSION);++ try (IndexOutput output = dir.createOutput(fileName, ioContext)) {+ // Only add the file once we've successfully created it, else IFD assert can trip:+ si.addFile(fileName);+ CodecUtil.writeIndexHeader(output,+ Lucene62SegmentInfoFormat.CODEC_NAME,+ Lucene62SegmentInfoFormat.VERSION_CURRENT,+ si.getId(),+ "");+ Version version = si.getVersion();+ if (version.major < 5) {+ throw new IllegalArgumentException("invalid major version: should be >= 5 but got: " + version.major + " segment=" + si);+ }+ // Write the Lucene version that created this segment, since 3.1+ output.writeInt(version.major);+ output.writeInt(version.minor);+ output.writeInt(version.bugfix);+ assert version.prerelease == 0;+ output.writeInt(si.maxDoc());++ output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));+ output.writeMapOfStrings(si.getDiagnostics());+ Set<String> files = si.files();+ for (String file : files) {+ if (!IndexFileNames.parseSegmentName(file).equals(si.name)) {+ throw new IllegalArgumentException("invalid files: expected segment=" + si.name + ", got=" + files);+ }+ }+ output.writeSetOfStrings(files);+ output.writeMapOfStrings(si.getAttributes());++ Sort indexSort = si.getIndexSort();+ int numSortFields = indexSort == null ? 0 : indexSort.getSort().length;+ output.writeVInt(numSortFields);+ for (int i = 0; i < numSortFields; ++i) {+ SortField sortField = indexSort.getSort()[i];+ output.writeString(sortField.getField());+ int sortTypeID;+ switch (sortField.getType()) {+ case STRING:+ sortTypeID = 0;+ break;+ case LONG:+ sortTypeID = 1;+ break;+ case INT:+ sortTypeID = 2;+ break;+ // nocommit the rest:+ default:+ throw new IllegalStateException("Unexpected sort type: " + sortField.getType());+ }+ output.writeVInt(sortTypeID);+ output.writeByte((byte) (sortField.getReverse() ? 0 : 1));++ // write missing value+ Object missingValue = sortField.getMissingValue();+ if (missingValue == null) {+ output.writeByte((byte) 0);+ } else {+ switch(sortField.getType()) {+ case STRING:+ if (missingValue == SortField.STRING_LAST) {+ output.writeByte((byte) 1);+ } else if (missingValue == SortField.STRING_FIRST) {+ output.writeByte((byte) 2);+ } else {+ throw new AssertionError("unrecognized missing value for STRING field \"" + sortField.getField() + "\": " + missingValue);+ }+ break;+ case LONG:+ output.writeByte((byte) 1);+ output.writeLong(((Long) missingValue).longValue());+ break;+ case INT:+ output.writeByte((byte) 1);+ output.writeInt(((Integer) missingValue).intValue());+ break;+ // nocommit the rest:+ default:+ throw new IllegalStateException("Unexpected sort type: " + sortField.getType());+ }+ }+ }++ CodecUtil.writeFooter(output);+ }+ }++ /** File extension used to store {@link SegmentInfo}. */+ public final static String SI_EXTENSION = "si";+ static final String CODEC_NAME = "Lucene62SegmentInfo";+ static final int VERSION_START = 0;+ static final int VERSION_CURRENT = VERSION_START;+}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene62/package-info.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene62/package-info.javanew file mode 100644index 00000000000..2fe2dc74b4a--- /dev/null+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene62/package-info.java@@ -0,0 +1,24 @@+/*+ * 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.+ */++/**+ * Components from the Lucene 6.2 index format+ * See {@link org.apache.lucene.codecs.lucene62} for an overview+ * of the index format.+ */++package org.apache.lucene.codecs.lucene62;diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.javaindex 5a68a3d0f66..fb2dc80ce3f 100644--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java@@ -43,6 +43,9 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.DocumentStoredFieldVisitor;import org.apache.lucene.index.CheckIndex.Status.DocValuesStatus;import org.apache.lucene.search.DocIdSetIterator;+import org.apache.lucene.search.LeafFieldComparator;+import org.apache.lucene.search.Sort;+import org.apache.lucene.search.SortField;import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;@@ -217,6 +220,9 @@ public final class CheckIndex implements Closeable {/** Status for testing of PointValues (null if PointValues could not be tested). */public PointsStatus pointsStatus;++ /** Status of index sort */+ public IndexSortStatus indexSortStatus;}/**@@ -374,6 +380,16 @@ public final class CheckIndex implements Closeable {/** Exception thrown during doc values test (null on success) */public Throwable error = null;}++ /**+ * Status from testing index sort+ */+ public static final class IndexSortStatus {++ /** Exception thrown during term index test (null on success) */+ public Throwable error = null;+ }+}/** Create a new CheckIndex on the directory. */@@ -642,6 +658,10 @@ public final class CheckIndex implements Closeable {msg(infoStream, " compound=" + info.info.getUseCompoundFile());segInfoStat.compound = info.info.getUseCompoundFile();msg(infoStream, " numFiles=" + info.files().size());+ Sort indexSort = info.info.getIndexSort();+ if (indexSort != null) {+ msg(infoStream, " sort=" + indexSort);+ }segInfoStat.numFiles = info.files().size();segInfoStat.sizeMB = info.sizeInBytes()/(1024.*1024.);msg(infoStream, " size (MB)=" + nf.format(segInfoStat.sizeMB));@@ -722,6 +742,9 @@ public final class CheckIndex implements Closeable {// Test PointValuessegInfoStat.pointsStatus = testPoints(reader, infoStream, failFast);+ // Test index sort+ segInfoStat.indexSortStatus = testSort(reader, indexSort, infoStream, failFast);+// Rethrow the first exception we encountered// This will cause stats for failed segments to be incremented properlyif (segInfoStat.liveDocStatus.error != null) {@@ -790,6 +813,70 @@ public final class CheckIndex implements Closeable {return result;}++ public static Status.IndexSortStatus testSort(CodecReader reader, Sort sort, PrintStream infoStream, boolean failFast) throws IOException {+ // This segment claims its documents are sorted according to the incoming sort ... let's make sure:++ long startNS = System.nanoTime();++ Status.IndexSortStatus status = new Status.IndexSortStatus();++ if (sort != null) {+ if (infoStream != null) {+ infoStream.print(" test: check index sort.....");+ }++ SortField fields[] = sort.getSort();+ final int reverseMul[] = new int[fields.length];+ final LeafFieldComparator comparators[] = new LeafFieldComparator[fields.length];++ LeafReaderContext readerContext = new LeafReaderContext(reader);++ for (int i = 0; i < fields.length; i++) {+ reverseMul[i] = fields[i].getReverse() ? -1 : 1;+ comparators[i] = fields[i].getComparator(1, i).getLeafComparator(readerContext);+ // nocommit we prevent SCORE?+ //comparators[i].setScorer(FAKESCORER);+ }++ int maxDoc = reader.maxDoc();++ try {++ for(int docID=1;docID < maxDoc;docID++) {++ int cmp = 0;++ for (int i = 0; i < comparators.length; i++) {+ // TODO: would be better if copy() didnt cause a term lookup in TermOrdVal & co,+ // the segments are always the same here...+ comparators[i].copy(0, docID-1);+ comparators[i].setBottom(0);+ cmp = reverseMul[i] * comparators[i].compareBottom(docID);+ if (cmp != 0) {+ break;+ }+ }++ if (cmp > 0) {+ throw new RuntimeException("segment has indexSort=" + sort + " but docID=" + (docID-1) + " sorts after docID=" + docID);+ }+ }+ msg(infoStream, String.format(Locale.ROOT, "OK [took %.3f sec]", nsToSec(System.nanoTime()-startNS)));+ } catch (Throwable e) {+ if (failFast) {+ IOUtils.reThrow(e);+ }+ msg(infoStream, "ERROR [" + String.valueOf(e.getMessage()) + "]");+ status.error = e;+ if (infoStream != null) {+ e.printStackTrace(infoStream);+ }+ }+ }++ return status;+ }/*** Test live docs.diff --git a/lucene/core/src/java/org/apache/lucene/index/MappingMultiPostingsEnum.java b/lucene/core/src/java/org/apache/lucene/index/MappingMultiPostingsEnum.javaindex c4333bc049d..41c2a46f218 100644--- a/lucene/core/src/java/org/apache/lucene/index/MappingMultiPostingsEnum.java+++ b/lucene/core/src/java/org/apache/lucene/index/MappingMultiPostingsEnum.java@@ -62,7 +62,6 @@ final class MappingMultiPostingsEnum extends PostingsEnum {this.field = field;allSubs = new MappingPostingsSub[mergeState.fieldsProducers.length];for(int i=0;i<allSubs.length;i++) {- // nocommit delDocMaps?allSubs[i] = new MappingPostingsSub(mergeState.docMaps[i], mergeState.liveDocs[i]);}this.docIDMerger = new DocIDMerger<MappingPostingsSub>(subs, allSubs.length, mergeState.segmentInfo.getIndexSort() != null);@@ -89,7 +88,11 @@ final class MappingMultiPostingsEnum extends PostingsEnum {@Overridepublic int docID() {- return current.mappedDocID;+ if (current == null) {+ return -1;+ } else {+ return current.mappedDocID;+ }}@Overridediff --git a/lucene/core/src/java/org/apache/lucene/index/Sorter.java b/lucene/core/src/java/org/apache/lucene/index/Sorter.javaindex 0ce7d64e0d1..cf75c18f6f0 100644--- a/lucene/core/src/java/org/apache/lucene/index/Sorter.java+++ b/lucene/core/src/java/org/apache/lucene/index/Sorter.java@@ -33,7 +33,6 @@ import org.apache.lucene.util.packed.PackedLongValues;* IDs.* @lucene.experimental*/-// nocommit rename to IndexSorter?final class Sorter {final Sort sort;diff --git a/lucene/core/src/java/org/apache/lucene/index/SortingLeafReader.java b/lucene/core/src/java/org/apache/lucene/index/SortingLeafReader.javaindex 45d44828978..b6558f7fd15 100644--- a/lucene/core/src/java/org/apache/lucene/index/SortingLeafReader.java+++ b/lucene/core/src/java/org/apache/lucene/index/SortingLeafReader.java@@ -337,10 +337,7 @@ class SortingLeafReader extends FilterLeafReader {@Overridepublic long nextOrd() {- // nocommit- long v = in.nextOrd();- //System.out.println(" slr.sssdv.nextOrd return " + v + " this=" + this);- return v;+ return in.nextOrd();}@Overridediff --git a/lucene/core/src/resources/META-INF/services/org.apache.lucene.codecs.Codec b/lucene/core/src/resources/META-INF/services/org.apache.lucene.codecs.Codecindex 875aba527e2..548f8d09244 100644--- a/lucene/core/src/resources/META-INF/services/org.apache.lucene.codecs.Codec+++ b/lucene/core/src/resources/META-INF/services/org.apache.lucene.codecs.Codec@@ -13,4 +13,4 @@# See the License for the specific language governing permissions and# limitations under the License.-org.apache.lucene.codecs.lucene60.Lucene60Codec+org.apache.lucene.codecs.lucene62.Lucene62Codecdiff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.javaindex 59e48144d44..f945c2d0dc0 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java@@ -19,7 +19,7 @@ package org.apache.lucene.codecs.lucene50;import org.apache.lucene.codecs.Codec;import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode;-import org.apache.lucene.codecs.lucene60.Lucene60Codec;+import org.apache.lucene.codecs.lucene62.Lucene62Codec;import org.apache.lucene.document.Document;import org.apache.lucene.document.StoredField;import org.apache.lucene.index.BaseStoredFieldsFormatTestCase;@@ -33,7 +33,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks;public class TestLucene50StoredFieldsFormatHighCompression extends BaseStoredFieldsFormatTestCase {@Overrideprotected Codec getCodec() {- return new Lucene60Codec(Mode.BEST_COMPRESSION);+ return new Lucene62Codec(Mode.BEST_COMPRESSION);}/**@@ -44,7 +44,7 @@ public class TestLucene50StoredFieldsFormatHighCompression extends BaseStoredFieDirectory dir = newDirectory();for (int i = 0; i < 10; i++) {IndexWriterConfig iwc = newIndexWriterConfig();- iwc.setCodec(new Lucene60Codec(RandomPicks.randomFrom(random(), Mode.values())));+ iwc.setCodec(new Lucene62Codec(RandomPicks.randomFrom(random(), Mode.values())));IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig());Document doc = new Document();doc.add(new StoredField("field1", "value1"));@@ -71,7 +71,7 @@ public class TestLucene50StoredFieldsFormatHighCompression extends BaseStoredFiepublic void testInvalidOptions() throws Exception {expectThrows(NullPointerException.class, () -> {- new Lucene60Codec(null);+ new Lucene62Codec(null);});expectThrows(NullPointerException.class, () -> {diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene53/TestLucene53NormsFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene53/TestLucene53NormsFormat.javaindex c915de0bfce..a0ad87fca87 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene53/TestLucene53NormsFormat.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene53/TestLucene53NormsFormat.java@@ -18,14 +18,14 @@ package org.apache.lucene.codecs.lucene53;import org.apache.lucene.codecs.Codec;-import org.apache.lucene.codecs.lucene60.Lucene60Codec;+import org.apache.lucene.codecs.lucene62.Lucene62Codec;import org.apache.lucene.index.BaseNormsFormatTestCase;/*** Tests Lucene53NormsFormat*/public class TestLucene53NormsFormat extends BaseNormsFormatTestCase {- private final Codec codec = new Lucene60Codec();+ private final Codec codec = new Lucene62Codec();@Overrideprotected Codec getCodec() {diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50SegmentInfoFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene62/TestLucene62SegmentInfoFormat.javasimilarity index 89%rename from lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50SegmentInfoFormat.javarename to lucene/core/src/test/org/apache/lucene/codecs/lucene62/TestLucene62SegmentInfoFormat.javaindex 81143300ee5..8c758f29e5a 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50SegmentInfoFormat.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene62/TestLucene62SegmentInfoFormat.java@@ -1,3 +1,5 @@+package org.apache.lucene.codecs.lucene62;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -14,8 +16,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-package org.apache.lucene.codecs.lucene50;-import org.apache.lucene.codecs.Codec;import org.apache.lucene.index.BaseSegmentInfoFormatTestCase;@@ -23,9 +23,9 @@ import org.apache.lucene.util.TestUtil;import org.apache.lucene.util.Version;/**- * Tests Lucene50SegmentInfoFormat+ * Tests Lucene62SegmentInfoFormat*/-public class TestLucene50SegmentInfoFormat extends BaseSegmentInfoFormatTestCase {+public class TestLucene62SegmentInfoFormat extends BaseSegmentInfoFormatTestCase {@Overrideprotected Version[] getVersions() {diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BPoints.java b/lucene/core/src/test/org/apache/lucene/index/Test2BPoints.javaindex 2f3a3a69890..da8dbac0f5e 100644--- a/lucene/core/src/test/org/apache/lucene/index/Test2BPoints.java+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BPoints.java@@ -24,8 +24,6 @@ import org.apache.lucene.codecs.FilterCodec;import org.apache.lucene.codecs.PointsFormat;import org.apache.lucene.codecs.PointsReader;import org.apache.lucene.codecs.PointsWriter;-import org.apache.lucene.codecs.lucene60.Lucene60PointsReader;-import org.apache.lucene.codecs.lucene60.Lucene60PointsWriter;import org.apache.lucene.document.Document;import org.apache.lucene.document.LongPoint;import org.apache.lucene.search.IndexSearcher;@@ -143,6 +141,6 @@ public class Test2BPoints extends LuceneTestCase {}private static Codec getCodec() {- return Codec.forName("Lucene60");+ return Codec.forName("Lucene62");}}diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java b/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.javaindex 22b3605965b..22d12346d4e 100644--- a/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java@@ -53,7 +53,7 @@ import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;// disk (but, should run successfully). Best to run w/// -Dtests.codec=<current codec>, and w/ plenty of RAM, eg://-// ant test -Dtests.monster=true -Dtests.heapsize=8g -Dtests.codec=Lucene60 -Dtestcase=Test2BTerms+// ant test -Dtests.monster=true -Dtests.heapsize=8g -Dtests.codec=Lucene62 -Dtestcase=Test2BTerms//@SuppressCodecs({ "SimpleText", "Memory", "Direct" })@Monster("very slow, use 5g minimum heap")diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.javaindex 2635b00ada7..8df81bab264 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java@@ -33,7 +33,6 @@ import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;-import org.apache.lucene.codecs.simpletext.SimpleTextCodec;import org.apache.lucene.document.BinaryDocValuesField;import org.apache.lucene.document.BinaryPoint;import org.apache.lucene.document.Document;@@ -76,16 +75,17 @@ import org.junit.BeforeClass;// nocommit test EarlyTerminatingCollector+// nocommit must test all supported SortField.Type+public class TestIndexSorting extends LuceneTestCase {public void testSortOnMerge(boolean withDeletes) throws IOException {Directory dir = newDirectory();IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));- iwc.setCodec(new SimpleTextCodec()); // nocommit only simple-text supports sorting so farSort indexSort = new Sort(new SortField("foo", SortField.Type.LONG));iwc.setIndexSort(indexSort);IndexWriter w = new IndexWriter(dir, iwc);- final int numDocs = atLeast(200);+ final int numDocs = atLeast(1000);final FixedBitSet deleted = new FixedBitSet(numDocs);for (int i = 0; i < numDocs; ++i) {Document doc = new Document();@@ -212,7 +212,6 @@ public class TestIndexSorting extends LuceneTestCase {public void testConcurrentUpdates() throws Exception {Directory dir = newDirectory();IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));- iwc.setCodec(new SimpleTextCodec()); // nocommit only simple-text supports sorting so farSort indexSort = new Sort(new SortField("foo", SortField.Type.LONG));iwc.setIndexSort(indexSort);IndexWriter w = new IndexWriter(dir, iwc);@@ -303,7 +302,6 @@ public class TestIndexSorting extends LuceneTestCase {public void testConcurrentDVUpdates() throws Exception {Directory dir = newDirectory();IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));- iwc.setCodec(new SimpleTextCodec()); // nocommit only simple-text supports sorting so farSort indexSort = new Sort(new SortField("foo", SortField.Type.LONG));iwc.setIndexSort(indexSort);IndexWriter w = new IndexWriter(dir, iwc);@@ -314,6 +312,7 @@ public class TestIndexSorting extends LuceneTestCase {Document doc = new Document();doc.add(new StringField("id", Integer.toString(i), Store.NO));doc.add(new NumericDocValuesField("foo", -1));+ w.addDocument(doc);values.put(i, -1L);}Thread[] threads = new Thread[2];@@ -321,7 +320,7 @@ public class TestIndexSorting extends LuceneTestCase {final CountDownLatch latch = new CountDownLatch(1);for (int i = 0; i < threads.length; ++i) {Random r = new Random(random().nextLong());- threads[i] = new Thread(new UpdateRunnable(numDocs, r, latch, updateCount, w, values));+ threads[i] = new Thread(new DVUpdateRunnable(numDocs, r, latch, updateCount, w, values));}for (Thread thread : threads) {thread.start();@@ -362,7 +361,6 @@ public class TestIndexSorting extends LuceneTestCase {Directory dir2 = newDirectory();IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));- iwc.setCodec(new SimpleTextCodec()); // nocommit only simple-text supports sorting so farSort indexSort = new Sort(new SortField("foo", SortField.Type.LONG));iwc.setIndexSort(indexSort);IndexWriter w2 = new IndexWriter(dir2, iwc);@@ -410,7 +408,6 @@ public class TestIndexSorting extends LuceneTestCase {public void testIllegalChangeSort() throws Exception {final Directory dir = newDirectory();IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));- iwc.setCodec(new SimpleTextCodec()); // nocommit only simple-text supports sorting so fariwc.setIndexSort(new Sort(new SortField("foo", SortField.Type.LONG)));IndexWriter w = new IndexWriter(dir, iwc);w.addDocument(new Document());@@ -420,12 +417,13 @@ public class TestIndexSorting extends LuceneTestCase {w.close();final IndexWriterConfig iwc2 = new IndexWriterConfig(new MockAnalyzer(random()));- iwc2.setCodec(new SimpleTextCodec()); // nocommit only simple-text supports sorting so fariwc2.setIndexSort(new Sort(new SortField("bar", SortField.Type.LONG)));- IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {+ IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {new IndexWriter(dir, iwc2);});- assertEquals("cannot change previous indexSort=<long: \"foo\"> (from segment=_2(7.0.0):c2:[indexSort=<long: \"foo\">]) to new indexSort=<long: \"bar\">", expected.getMessage());+ String message = e.getMessage();+ assertTrue(message.contains("cannot change previous indexSort=<long: \"foo\">"));+ assertTrue(message.contains("to new indexSort=<long: \"bar\">"));dir.close();}@@ -574,8 +572,6 @@ public class TestIndexSorting extends LuceneTestCase {PositionsTokenStream positions = new PositionsTokenStream();IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));- // nocommit:- conf.setCodec(new SimpleTextCodec());conf.setMaxBufferedDocs(4); // create some segmentsconf.setSimilarity(new NormsSimilarity(conf.getSimilarity())); // for testing norms field// nocommit@@ -633,7 +629,6 @@ public class TestIndexSorting extends LuceneTestCase {assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef(DOC_POSITIONS_TERM)));PostingsEnum sortedPositions = termsEnum.postings(null, PostingsEnum.ALL);int doc;- boolean isSorted = reader.getIndexSort() != null;// test nextDoc()while ((doc = sortedPositions.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {@@ -687,7 +682,6 @@ public class TestIndexSorting extends LuceneTestCase {LeafReader reader = ctx.reader();NumericDocValues dv = reader.getNormValues(NORMS_FIELD);int maxDoc = reader.maxDoc();- boolean isSorted = reader.getIndexSort() != null;for (int doc = 0; doc < maxDoc; doc++) {int id = Integer.parseInt(reader.document(doc).get(ID_FIELD));assertEquals("incorrect norm value for doc " + doc, id, dv.get(doc));diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.javaindex 9f55ec3fdcc..9693c5c32b1 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java@@ -394,11 +394,11 @@ public class TestPointValues extends LuceneTestCase {dir.close();}- // Write point values, one segment with Lucene60, another with SimpleText, then forceMerge with SimpleText+ // Write point values, one segment with Lucene62, another with SimpleText, then forceMerge with SimpleTextpublic void testDifferentCodecs1() throws Exception {Directory dir = newDirectory();IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));- iwc.setCodec(Codec.forName("Lucene60"));+ iwc.setCodec(Codec.forName("Lucene62"));IndexWriter w = new IndexWriter(dir, iwc);Document doc = new Document();doc.add(new IntPoint("int", 1));@@ -417,7 +417,7 @@ public class TestPointValues extends LuceneTestCase {dir.close();}- // Write point values, one segment with Lucene60, another with SimpleText, then forceMerge with Lucene60+ // Write point values, one segment with Lucene62, another with SimpleText, then forceMerge with Lucene60public void testDifferentCodecs2() throws Exception {Directory dir = newDirectory();IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));@@ -429,7 +429,7 @@ public class TestPointValues extends LuceneTestCase {w.close();iwc = new IndexWriterConfig(new MockAnalyzer(random()));- iwc.setCodec(Codec.forName("Lucene60"));+ iwc.setCodec(Codec.forName("Lucene62"));w = new IndexWriter(dir, iwc);doc = new Document();doc.add(new IntPoint("int", 1));diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.javaindex 88d89d29417..078c8da3653 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java@@ -1151,14 +1151,14 @@ public class TestPointQueries extends LuceneTestCase {}private static Codec getCodec() {- if (Codec.getDefault().getName().equals("Lucene60")) {+ if (Codec.getDefault().getName().equals("Lucene62")) {int maxPointsInLeafNode = TestUtil.nextInt(random(), 16, 2048);double maxMBSortInHeap = 5.0 + (3*random().nextDouble());if (VERBOSE) {System.out.println("TEST: using Lucene60PointsFormat with maxPointsInLeafNode=" + maxPointsInLeafNode + " and maxMBSortInHeap=" + maxMBSortInHeap);}- return new FilterCodec("Lucene60", Codec.getDefault()) {+ return new FilterCodec("Lucene62", Codec.getDefault()) {@Overridepublic PointsFormat pointsFormat() {return new PointsFormat() {diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TermVectorLeafReader.java b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TermVectorLeafReader.javaindex 4d76fa9dd39..55f360ad308 100644--- a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TermVectorLeafReader.java+++ b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TermVectorLeafReader.java@@ -21,7 +21,6 @@ import java.util.Collections;import java.util.Iterator;import org.apache.lucene.index.BinaryDocValues;-import org.apache.lucene.index.PointValues;import org.apache.lucene.index.DocValuesType;import org.apache.lucene.index.FieldInfo;import org.apache.lucene.index.FieldInfos;@@ -29,11 +28,13 @@ import org.apache.lucene.index.Fields;import org.apache.lucene.index.IndexOptions;import org.apache.lucene.index.LeafReader;import org.apache.lucene.index.NumericDocValues;+import org.apache.lucene.index.PointValues;import org.apache.lucene.index.SortedDocValues;import org.apache.lucene.index.SortedNumericDocValues;import org.apache.lucene.index.SortedSetDocValues;import org.apache.lucene.index.StoredFieldVisitor;import org.apache.lucene.index.Terms;+import org.apache.lucene.search.Sort;import org.apache.lucene.util.Bits;/**@@ -178,4 +179,8 @@ public class TermVectorLeafReader extends LeafReader {public void document(int docID, StoredFieldVisitor visitor) throws IOException {}+ @Override+ public Sort getIndexSort() {+ return null;+ }}diff --git a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.javaindex 5b133013ed5..e3aa4b14a13 100644--- a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java+++ b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java@@ -40,6 +40,7 @@ import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;import org.apache.lucene.search.Scorer;import org.apache.lucene.search.SimpleCollector;+import org.apache.lucene.search.Sort;import org.apache.lucene.search.similarities.Similarity;import org.apache.lucene.store.RAMDirectory;import org.apache.lucene.util.*;@@ -1606,6 +1607,10 @@ public class MemoryIndex {return info.getNormDocValues();}+ @Override+ public Sort getIndexSort() {+ return null;+ }}/**diff --git a/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java b/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.javaindex cf860a2ac20..54ad7445c79 100644--- a/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java+++ b/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java@@ -35,7 +35,6 @@ import org.apache.lucene.index.LeafReaderContext;import org.apache.lucene.index.MultiDocValues;import org.apache.lucene.index.NumericDocValues;import org.apache.lucene.index.RandomIndexWriter;-import org.apache.lucene.index.SlowCompositeReaderWrapper;import org.apache.lucene.index.SortedDocValues;import org.apache.lucene.index.Term;import org.apache.lucene.search.BooleanClause.Occur;diff --git a/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java b/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.javaindex 3bcc4924327..6108992ce67 100644--- a/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java+++ b/lucene/misc/src/test/org/apache/lucene/search/TestEarlyTerminatingSortingCollector.java@@ -50,8 +50,6 @@ import org.apache.lucene.search.SortField;import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.TopFieldCollector;import org.apache.lucene.store.Directory;-import org.apache.lucene.uninverting.UninvertingReader.Type;-import org.apache.lucene.uninverting.UninvertingReader;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.TestUtil;@@ -236,27 +234,12 @@ public class TestEarlyTerminatingSortingCollector extends LuceneTestCase {}}- private IndexSearcher newSearcherForTestTerminatedEarly(IndexReader r) throws IOException {- switch(random().nextInt(2)) {- case 0:- return new IndexSearcher(r);- case 1:- assertTrue(r+" is not a DirectoryReader", (r instanceof DirectoryReader));- final DirectoryReader directoryReader = ExitableDirectoryReader.wrap(- UninvertingReader.wrap((DirectoryReader) r, new HashMap<String,Type>()),- new TestEarlyTerminatingSortingcollectorQueryTimeout(false));- return new IndexSearcher(directoryReader);- }- fail("newSearcherForTestTerminatedEarly("+r+") fell through switch");- return null;- }-public void testTerminatedEarly() throws IOException {final int iters = atLeast(8);for (int i = 0; i < iters; ++i) {createRandomIndex(true);- final IndexSearcher searcher = newSearcherForTestTerminatedEarly(reader); // future TODO: use newSearcher(reader);+ final IndexSearcher searcher = new IndexSearcher(reader); // future TODO: use newSearcher(reader);final Query query = new MatchAllDocsQuery(); // search for everything/anythingfinal TestTerminatedEarlySimpleCollector collector1 = new TestTerminatedEarlySimpleCollector();diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestNearest.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestNearest.javaindex 66630df2bca..0b19254d985 100644--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestNearest.java+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestNearest.java@@ -247,7 +247,7 @@ public class TestNearest extends LuceneTestCase {private IndexWriterConfig getIndexWriterConfig() {IndexWriterConfig iwc = newIndexWriterConfig();- iwc.setCodec(Codec.forName("Lucene60"));+ iwc.setCodec(Codec.forName("Lucene62"));return iwc;}}diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.javaindex 0f8f2026fe4..c2cb93b13f0 100644--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java@@ -85,14 +85,14 @@ import com.carrotsearch.randomizedtesting.generators.RandomInts;public class TestGeo3DPoint extends LuceneTestCase {private static Codec getCodec() {- if (Codec.getDefault().getName().equals("Lucene60")) {+ if (Codec.getDefault().getName().equals("Lucene62")) {int maxPointsInLeafNode = TestUtil.nextInt(random(), 16, 2048);double maxMBSortInHeap = 3.0 + (3*random().nextDouble());if (VERBOSE) {System.out.println("TEST: using Lucene60PointsFormat with maxPointsInLeafNode=" + maxPointsInLeafNode + " and maxMBSortInHeap=" + maxMBSortInHeap);}- return new FilterCodec("Lucene60", Codec.getDefault()) {+ return new FilterCodec("Lucene62", Codec.getDefault()) {@Overridepublic PointsFormat pointsFormat() {return new PointsFormat() {diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.javaindex 2b14d6e8016..004aef44d94 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java@@ -56,7 +56,6 @@ import org.apache.lucene.index.MultiDocValues;import org.apache.lucene.index.ReaderUtil;import org.apache.lucene.index.SegmentReader;import org.apache.lucene.index.SortedSetDocValues;-import org.apache.lucene.index.SortingMergePolicy;import org.apache.lucene.index.Term;import org.apache.lucene.search.BooleanClause.Occur;import org.apache.lucene.search.BooleanClause;@@ -232,7 +231,7 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {// This way all merged segments will be sorted at// merge time, allow for per-segment early termination// when those segments are searched:- iwc.setMergePolicy(new SortingMergePolicy(iwc.getMergePolicy(), SORT));+ iwc.setIndexSort(SORT);return iwc;}@@ -586,8 +585,7 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {// We sorted postings by weight during indexing, so we// only retrieve the first num hits now:- final SortingMergePolicy sortingMergePolicy = (SortingMergePolicy) writer.getConfig().getMergePolicy();- Collector c2 = new EarlyTerminatingSortingCollector(c, SORT, num, sortingMergePolicy.getSort());+ Collector c2 = new EarlyTerminatingSortingCollector(c, SORT, num);IndexSearcher searcher = searcherMgr.acquire();List<LookupResult> results = null;try {diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.javaindex 62ed08b8d0e..6b1c2d1b21d 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java@@ -32,7 +32,7 @@ import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.codecs.Codec;import org.apache.lucene.codecs.PostingsFormat;-import org.apache.lucene.codecs.lucene60.Lucene60Codec;+import org.apache.lucene.codecs.lucene62.Lucene62Codec;import org.apache.lucene.document.IntPoint;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -646,7 +646,7 @@ public class TestSuggestField extends LuceneTestCase {static IndexWriterConfig iwcWithSuggestField(Analyzer analyzer, final Set<String> suggestFields) {IndexWriterConfig iwc = newIndexWriterConfig(random(), analyzer);iwc.setMergePolicy(newLogMergePolicy());- Codec filterCodec = new Lucene60Codec() {+ Codec filterCodec = new Lucene62Codec() {PostingsFormat postingsFormat = new Completion50PostingsFormat();@Overridediff --git a/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.javaindex bda4cdebaad..275c1864857 100644--- a/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/geo/BaseGeoPointTestCase.java@@ -1242,7 +1242,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {// Else seeds may not reproduce:iwc.setMergeScheduler(new SerialMergeScheduler());int pointsInLeaf = 2 + random().nextInt(4);- iwc.setCodec(new FilterCodec("Lucene60", TestUtil.getDefaultCodec()) {+ iwc.setCodec(new FilterCodec("Lucene62", TestUtil.getDefaultCodec()) {@Overridepublic PointsFormat pointsFormat() {return new PointsFormat() {diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.javaindex 27e01c1fbef..49d19ae4322 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java@@ -163,8 +163,14 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatT}}+ protected boolean supportsIndexSort() {+ return true;+ }+/** Test sort */public void testSort() throws IOException {+ assumeTrue("test requires a codec that can read/write index sort", supportsIndexSort());+final int iters = atLeast(5);for (int i = 0; i < iters; ++i) {Sort sort;diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.javaindex 7ac40375f15..5c88dc7ec92 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java@@ -32,7 +32,7 @@ import org.apache.lucene.codecs.asserting.AssertingPostingsFormat;import org.apache.lucene.codecs.cheapbastard.CheapBastardCodec;import org.apache.lucene.codecs.compressing.CompressingCodec;import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat;-import org.apache.lucene.codecs.lucene60.Lucene60Codec;+import org.apache.lucene.codecs.lucene62.Lucene62Codec;import org.apache.lucene.codecs.mockrandom.MockRandomPostingsFormat;import org.apache.lucene.codecs.simpletext.SimpleTextCodec;import org.apache.lucene.index.RandomCodec;@@ -181,8 +181,8 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {codec = new AssertingCodec();} else if ("Compressing".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 6 && !shouldAvoidCodec("Compressing"))) {codec = CompressingCodec.randomInstance(random);- } else if ("Lucene60".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 5 && !shouldAvoidCodec("Lucene60"))) {- codec = new Lucene60Codec(RandomPicks.randomFrom(random, Lucene50StoredFieldsFormat.Mode.values()));+ } else if ("Lucene62".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 5 && !shouldAvoidCodec("Lucene62"))) {+ codec = new Lucene62Codec(RandomPicks.randomFrom(random, Lucene50StoredFieldsFormat.Mode.values()));} else if (!"random".equals(TEST_CODEC)) {codec = Codec.forName(TEST_CODEC);} else if ("random".equals(TEST_POSTINGSFORMAT)) {diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.javaindex d772ae321d3..b63216085b3 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java@@ -54,7 +54,7 @@ import org.apache.lucene.codecs.blockterms.LuceneFixedGap;import org.apache.lucene.codecs.blocktreeords.BlockTreeOrdsPostingsFormat;import org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat;import org.apache.lucene.codecs.lucene54.Lucene54DocValuesFormat;-import org.apache.lucene.codecs.lucene60.Lucene60Codec;+import org.apache.lucene.codecs.lucene62.Lucene62Codec;import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;import org.apache.lucene.document.BinaryDocValuesField;@@ -911,7 +911,7 @@ public final class TestUtil {* This may be different than {@link Codec#getDefault()} because that is randomized.*/public static Codec getDefaultCodec() {- return new Lucene60Codec();+ return new Lucene62Codec();}/**