Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ public long updateBinaryDocValue(Term term, String field, BytesRef value) throws
if (value == null) {
throw new IllegalArgumentException("cannot update a field to a null value: " + field);
}
globalFieldNumberMap.verifyOrCreateDvOnlyField(field, DocValuesType.BINARY, true);
globalFieldNumberMap.verifyOrCreateDvOnlyField(field, DocValuesType.BINARY, false);
try {
return maybeProcessEvents(
docWriter.updateDocValues(new BinaryDocValuesUpdate(term, field, value)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,41 @@ public void testSimple() throws Exception {
dir.close();
}

public void testSimpleAddBDVFieldViaUpdate() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
// make sure random config doesn't flush on us
conf.setMaxBufferedDocs(10);
conf.setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH);
IndexWriter writer = new IndexWriter(dir, conf);
writer.addDocument(doc(0)); // val=1
writer.addDocument(doc(1)); // val=2
if (random().nextBoolean()) { // randomly commit before the update is sent
writer.commit();
}
writer.updateBinaryDocValue(new Term("id", "doc-0"), "new", toBytes(2)); // doc=0, exp=2

final DirectoryReader reader;
if (random().nextBoolean()) { // not NRT
writer.close();
reader = DirectoryReader.open(dir);
} else { // NRT
reader = DirectoryReader.open(writer);
writer.close();
}

assertEquals(1, reader.leaves().size());
LeafReader r = reader.leaves().get(0).reader();
BinaryDocValues bdv = r.getBinaryDocValues("new");
assertEquals(0, bdv.nextDoc());
assertEquals(2, getValue(bdv));
assertEquals(NO_MORE_DOCS, bdv.nextDoc());
// assertEquals(2, getValue(bdv));
reader.close();

dir.close();
}

public void testUpdateFewSegments() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
Expand Down Expand Up @@ -463,11 +498,12 @@ public void testUpdateNonBinaryDocValuesField() throws Exception {
writer.commit();
writer.addDocument(doc); // in-memory document

expectThrows(
IllegalArgumentException.class,
() -> {
writer.updateBinaryDocValue(new Term("key", "doc"), "bdv", toBytes(17L));
});
// expectThrows(
// IllegalArgumentException.class,
// () -> {
// now we accept adding bdv field
writer.updateBinaryDocValue(new Term("key", "doc"), "bdv", toBytes(17L));
// });

expectThrows(
IllegalArgumentException.class,
Expand Down
Loading