mirror of
https://github.com/apache/lucene.git
synced 2025-02-10 03:55:46 +00:00
LUCENE-8050: PerFieldDocValuesFormat should not get the DocValuesFormat on a field that has no doc values.
Closes #1408
This commit is contained in:
parent
529042e786
commit
de6233976a
@ -131,6 +131,9 @@ Improvements
|
|||||||
|
|
||||||
* LUCENE-9279: Update dictionary version for Ukrainian analyzer to 4.9.1 (Andriy Rysin via Dawid Weiss)
|
* 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
|
Optimizations
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
@ -135,6 +135,9 @@ public abstract class PerFieldDocValuesFormat extends DocValuesFormat {
|
|||||||
|
|
||||||
// Group each consumer by the fields it handles
|
// Group each consumer by the fields it handles
|
||||||
for (FieldInfo fi : mergeState.mergeFieldInfos) {
|
for (FieldInfo fi : mergeState.mergeFieldInfos) {
|
||||||
|
if (fi.getDocValuesType() == DocValuesType.NONE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// merge should ignore current format for the fields being merged
|
// merge should ignore current format for the fields being merged
|
||||||
DocValuesConsumer consumer = getInstance(fi, true);
|
DocValuesConsumer consumer = getInstance(fi, true);
|
||||||
Collection<String> fieldsForConsumer = consumersToField.get(consumer);
|
Collection<String> fieldsForConsumer = consumersToField.get(consumer);
|
||||||
|
@ -36,6 +36,7 @@ import org.apache.lucene.document.BinaryDocValuesField;
|
|||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.NumericDocValuesField;
|
import org.apache.lucene.document.NumericDocValuesField;
|
||||||
|
import org.apache.lucene.document.TextField;
|
||||||
import org.apache.lucene.index.BaseDocValuesFormatTestCase;
|
import org.apache.lucene.index.BaseDocValuesFormatTestCase;
|
||||||
import org.apache.lucene.index.BinaryDocValues;
|
import org.apache.lucene.index.BinaryDocValues;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
@ -65,7 +66,7 @@ public class TestPerFieldDocValuesFormat extends BaseDocValuesFormatTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
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();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +190,43 @@ public class TestPerFieldDocValuesFormat extends BaseDocValuesFormatTestCase {
|
|||||||
directory.close();
|
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 static final class MergeRecordingDocValueFormatWrapper extends DocValuesFormat {
|
||||||
private final DocValuesFormat delegate;
|
private final DocValuesFormat delegate;
|
||||||
final List<String> fieldNames = new ArrayList<>();
|
final List<String> fieldNames = new ArrayList<>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user