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.java index bb52eebc06e..762b2c084bc 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62SegmentInfoFormat.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene62/Lucene62SegmentInfoFormat.java @@ -264,7 +264,6 @@ public class Lucene62SegmentInfoFormat extends SegmentInfoFormat { case FLOAT: sortTypeID = 4; break; - // nocommit the rest: default: throw new IllegalStateException("Unexpected sort type: " + sortField.getType()); } @@ -302,7 +301,6 @@ public class Lucene62SegmentInfoFormat extends SegmentInfoFormat { output.writeByte((byte) 1); output.writeLong(Float.floatToIntBits(((Float) missingValue).floatValue())); break; - // nocommit the rest: default: throw new IllegalStateException("Unexpected sort type: " + sortField.getType()); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java index 15d18fbb11c..278aadc333f 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java @@ -22,9 +22,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; @@ -610,7 +612,7 @@ public class TestIndexSorting extends LuceneTestCase { @Override public long computeNorm(FieldInvertState state) { - if (state.getName().equals(NORMS_FIELD)) { + if (state.getName().equals("norms")) { return Float.floatToIntBits(state.getBoost()); } else { return in.computeNorm(state); @@ -650,7 +652,7 @@ public class TestIndexSorting extends LuceneTestCase { } clearAttributes(); - term.append(DOC_POSITIONS_TERM); + term.append("#all#"); payload.setPayload(new BytesRef(Integer.toString(pos))); offset.setOffset(off, off); --pos; @@ -664,296 +666,94 @@ public class TestIndexSorting extends LuceneTestCase { } } - private static Directory dir; - private static IndexReader sortedReader; + // nocommit testrandom1 with deletions - private static final FieldType TERM_VECTORS_TYPE = new FieldType(TextField.TYPE_NOT_STORED); - static { - TERM_VECTORS_TYPE.setStoreTermVectors(true); - TERM_VECTORS_TYPE.freeze(); - } - - private static final FieldType POSITIONS_TYPE = new FieldType(TextField.TYPE_NOT_STORED); - static { - POSITIONS_TYPE.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); - POSITIONS_TYPE.freeze(); - } - - private static final String ID_FIELD = "id"; - private static final String DOCS_ENUM_FIELD = "docs"; - private static final String DOCS_ENUM_TERM = "$all$"; - private static final String DOC_POSITIONS_FIELD = "positions"; - private static final String DOC_POSITIONS_TERM = "$all$"; - private static final String NUMERIC_DV_FIELD = "numeric"; - private static final String SORTED_NUMERIC_DV_FIELD = "sorted_numeric"; - private static final String NORMS_FIELD = "norm"; - private static final String BINARY_DV_FIELD = "binary"; - private static final String SORTED_DV_FIELD = "sorted"; - private static final String SORTED_SET_DV_FIELD = "sorted_set"; - private static final String TERM_VECTORS_FIELD = "term_vectors"; - private static final String DIMENSIONAL_FIELD = "numeric1d"; - - private static Document doc(final int id, PositionsTokenStream positions) { - final Document doc = new Document(); - doc.add(new StringField(ID_FIELD, Integer.toString(id), Store.YES)); - doc.add(new StringField(DOCS_ENUM_FIELD, DOCS_ENUM_TERM, Store.NO)); - positions.setId(id); - doc.add(new Field(DOC_POSITIONS_FIELD, positions, POSITIONS_TYPE)); - doc.add(new NumericDocValuesField(NUMERIC_DV_FIELD, id)); - TextField norms = new TextField(NORMS_FIELD, Integer.toString(id), Store.NO); - norms.setBoost(Float.intBitsToFloat(id)); - doc.add(norms); - doc.add(new BinaryDocValuesField(BINARY_DV_FIELD, new BytesRef(Integer.toString(id)))); - doc.add(new SortedDocValuesField(SORTED_DV_FIELD, new BytesRef(Integer.toString(id)))); - doc.add(new SortedSetDocValuesField(SORTED_SET_DV_FIELD, new BytesRef(Integer.toString(id)))); - doc.add(new SortedSetDocValuesField(SORTED_SET_DV_FIELD, new BytesRef(Integer.toString(id + 1)))); - doc.add(new SortedNumericDocValuesField(SORTED_NUMERIC_DV_FIELD, id)); - doc.add(new SortedNumericDocValuesField(SORTED_NUMERIC_DV_FIELD, id + 1)); - doc.add(new Field(TERM_VECTORS_FIELD, Integer.toString(id), TERM_VECTORS_TYPE)); - byte[] bytes = new byte[4]; - NumericUtils.intToSortableBytes(id, bytes, 0); - doc.add(new BinaryPoint(DIMENSIONAL_FIELD, bytes)); - return doc; - } - - @AfterClass - public static void afterClass() throws Exception { - if (sortedReader != null) { - sortedReader.close(); - sortedReader = null; - } - if (dir != null) { - dir.close(); - dir = null; - } - } - - @BeforeClass - public static void createIndex() throws Exception { - dir = newFSDirectory(createTempDir()); + public void testRandom1() throws Exception { int numDocs = atLeast(100); - List ids = new ArrayList<>(); - for (int i = 0; i < numDocs; i++) { - ids.add(Integer.valueOf(i * 10)); + FieldType POSITIONS_TYPE = new FieldType(TextField.TYPE_NOT_STORED); + POSITIONS_TYPE.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); + POSITIONS_TYPE.freeze(); + + FieldType TERM_VECTORS_TYPE = new FieldType(TextField.TYPE_NOT_STORED); + TERM_VECTORS_TYPE.setStoreTermVectors(true); + TERM_VECTORS_TYPE.freeze(); + + List docs = new ArrayList<>(); + for (int i=0;i