Github user jpountz commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/516#discussion_r239407845
--- Diff:
lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
---
@@ -1587,6 +1590,76 @@ public void testDocValuesUpdates() throws Exception {
writer.close();
dir.close();
}
+
+ public void testSoftDeletes() throws Exception {
+ Path oldIndexDir = createTempDir("dvupdates");
+ TestUtil.unzip(getDataInputStream(dvUpdatesIndex), oldIndexDir);
+ Directory dir = newFSDirectory(oldIndexDir);
+ verifyUsesDefaultCodec(dir, dvUpdatesIndex);
+ IndexWriterConfig conf = new IndexWriterConfig(new
MockAnalyzer(random())).setSoftDeletesField("__soft_delete");
+ IndexWriter writer = new IndexWriter(dir, conf);
+ int maxDoc = writer.maxDoc();
+ writer.updateDocValues(new Term("id", "1"),new
NumericDocValuesField("__soft_delete", 1));
+
+ if (random().nextBoolean()) {
+ writer.commit();
+ }
+ writer.forceMerge(1);
+ writer.commit();
+ assertEquals(maxDoc-1, writer.maxDoc());
+ writer.close();
+ dir.close();
+ }
+
+ public void testDocValuesUpdatesWithNewField() throws Exception {
+ Path oldIndexDir = createTempDir("dvupdates");
+ TestUtil.unzip(getDataInputStream(dvUpdatesIndex), oldIndexDir);
+ Directory dir = newFSDirectory(oldIndexDir);
+ verifyUsesDefaultCodec(dir, dvUpdatesIndex);
+
+ // update fields and verify index
+ IndexWriterConfig conf = new IndexWriterConfig(new
MockAnalyzer(random()));
+ IndexWriter writer = new IndexWriter(dir, conf);
+ // introduce a new field that we later update
+ writer.addDocument(Arrays.asList(new StringField("id", "" +
Integer.MAX_VALUE, Field.Store.NO),
+ new NumericDocValuesField("new_numeric", 1),
+ new BinaryDocValuesField("new_binary", toBytes(1))));
+ writer.updateNumericDocValue(new Term("id", "1"), "new_numeric", 1);
+ writer.updateBinaryDocValue(new Term("id", "1"), "new_binary",
toBytes(1));
+
+ writer.commit();
+ Callable assertDV = () -> {
+ boolean found = false;
+ try (DirectoryReader reader = DirectoryReader.open(dir)) {
+ for (LeafReaderContext ctx : reader.leaves()) {
+ LeafReader leafReader = ctx.reader();
+ TermsEnum id = leafReader.terms("id").iterator();
+ if (id.seekExact(new BytesRef("1"))) {
+ PostingsEnum postings = id.postings(null, PostingsEnum.NONE);
+ NumericDocValues numericDocValues =
leafReader.getNumericDocValues("new_numeric");
+ BinaryDocValues binaryDocValues =
leafReader.getBinaryDocValues("new_binary");
+ int doc;
+ while ((doc = postings.nextDoc()) !=
DocIdSetIterator.NO_MORE_DOCS) {
+ found = true;
+ assertEquals(doc, binaryDocValues.nextDoc());
+ assertEquals(doc, numericDocValues.nextDoc());
+ assertEquals(1, numericDocValues.longValue());
+ assertEquals(toBytes(1), binaryDocValues.binaryValue());
+ }
+ }
--- End diff --
for completeness, add `assertEquals(DocIdSetIterator.NO_MORE_DOCS,
binaryDocValues.nextDoc()); assertEquals(DocIdSetIterator.NO_MORE_DOCS,
numericDocValues.nextDoc());`?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]