LUCENE-8050: PerFieldDocValuesFormat should not get the DocValuesFormat on a field that has no doc values.

Closes #1408
This commit is contained in:
Juan Camilo Rodriguez Duran 2020-04-07 16:11:25 -04:00 committed by David Smiley
parent 529042e786
commit de6233976a
3 changed files with 45 additions and 1 deletions

View File

@ -131,6 +131,9 @@ Improvements
* LUCENE-9279: Update dictionary version for Ukrainian analyzer to 4.9.1 (Andriy Rysin via Dawid Weiss)
* LUCENE-8050: PerFieldDocValuesFormat should not get the DocValuesFormat on a field that has no doc values.
(David Smiley, Juan Rodriguez)
Optimizations
---------------------

View File

@ -135,6 +135,9 @@ public abstract class PerFieldDocValuesFormat extends DocValuesFormat {
// Group each consumer by the fields it handles
for (FieldInfo fi : mergeState.mergeFieldInfos) {
if (fi.getDocValuesType() == DocValuesType.NONE) {
continue;
}
// merge should ignore current format for the fields being merged
DocValuesConsumer consumer = getInstance(fi, true);
Collection<String> fieldsForConsumer = consumersToField.get(consumer);

View File

@ -36,6 +36,7 @@ import org.apache.lucene.document.BinaryDocValuesField;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.BaseDocValuesFormatTestCase;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DirectoryReader;
@ -65,7 +66,7 @@ public class TestPerFieldDocValuesFormat extends BaseDocValuesFormatTestCase {
@Override
public void setUp() throws Exception {
codec = new RandomCodec(new Random(random().nextLong()), Collections.<String>emptySet());
codec = new RandomCodec(new Random(random().nextLong()), Collections.emptySet());
super.setUp();
}
@ -189,6 +190,43 @@ public class TestPerFieldDocValuesFormat extends BaseDocValuesFormatTestCase {
directory.close();
}
public void testDocValuesMergeWithIndexedFields() throws IOException {
MergeRecordingDocValueFormatWrapper docValuesFormat = new MergeRecordingDocValueFormatWrapper(TestUtil.getDefaultDocValuesFormat());
IndexWriterConfig iwc = new IndexWriterConfig();
iwc.setCodec(new AssertingCodec() {
@Override
public DocValuesFormat getDocValuesFormatForField(String field) {
return docValuesFormat;
}
});
Directory directory = newDirectory();
IndexWriter iwriter = new IndexWriter(directory, iwc);
Document doc = new Document();
doc.add(new NumericDocValuesField("dv1", 5));
doc.add(new TextField("normalField", "not a doc value", Field.Store.NO));
iwriter.addDocument(doc);
iwriter.commit();
doc = new Document();
doc.add(new TextField("anotherField", "again no doc values here", Field.Store.NO));
doc.add(new TextField("normalField", "my document without doc values", Field.Store.NO));
iwriter.addDocument(doc);
iwriter.commit();
iwriter.forceMerge(1, true);
iwriter.close();
// "normalField" and "anotherField" are ignored when merging doc values.
assertEquals(1, docValuesFormat.nbMergeCalls);
assertEquals(Collections.singletonList("dv1"), docValuesFormat.fieldNames);
directory.close();
}
private static final class MergeRecordingDocValueFormatWrapper extends DocValuesFormat {
private final DocValuesFormat delegate;
final List<String> fieldNames = new ArrayList<>();