mirror of https://github.com/apache/lucene.git
LUCENE-3623: SegmentReader.getFileNames was ignoring FieldOption.DOC_VALUES
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1211409 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b8834cda1b
commit
c0f0e06213
|
@ -31,6 +31,7 @@ import org.apache.lucene.index.codecs.FieldsConsumer;
|
|||
import org.apache.lucene.index.codecs.StoredFieldsWriter;
|
||||
import org.apache.lucene.index.codecs.PerDocConsumer;
|
||||
import org.apache.lucene.index.codecs.TermVectorsWriter;
|
||||
import org.apache.lucene.index.values.ValueType;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.IndexOutput;
|
||||
|
@ -202,7 +203,11 @@ final class SegmentMerger {
|
|||
addIndexed(reader, mergeState.fieldInfos, reader.getFieldNames(FieldOption.STORES_PAYLOADS), false, false, false, true, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
|
||||
addIndexed(reader, mergeState.fieldInfos, reader.getFieldNames(FieldOption.INDEXED), false, false, false, false, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
|
||||
mergeState.fieldInfos.addOrUpdate(reader.getFieldNames(FieldOption.UNINDEXED), false);
|
||||
mergeState.fieldInfos.addOrUpdate(reader.getFieldNames(FieldOption.DOC_VALUES), false);
|
||||
Collection<String> dvNames = reader.getFieldNames(FieldOption.DOC_VALUES);
|
||||
mergeState.fieldInfos.addOrUpdate(dvNames, false);
|
||||
for (String dvName : dvNames) {
|
||||
mergeState.fieldInfos.fieldInfo(dvName).setDocValues(reader.docValues(dvName).type());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -536,6 +536,9 @@ public class SegmentReader extends IndexReader implements Cloneable {
|
|||
else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) &&
|
||||
fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET) {
|
||||
fieldSet.add(fi.name);
|
||||
}
|
||||
else if (fi.hasDocValues() && fieldOption == IndexReader.FieldOption.DOC_VALUES) {
|
||||
fieldSet.add(fi.name);
|
||||
}
|
||||
}
|
||||
return fieldSet;
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
|
|||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.document.IndexDocValuesField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
|
@ -44,6 +45,7 @@ import org.apache.lucene.index.codecs.lucene40.Lucene40SegmentInfosFormat;
|
|||
import org.apache.lucene.index.codecs.lucene40.Lucene40StoredFieldsFormat;
|
||||
import org.apache.lucene.index.codecs.lucene40.Lucene40TermVectorsFormat;
|
||||
import org.apache.lucene.index.codecs.pulsing.Pulsing40PostingsFormat;
|
||||
import org.apache.lucene.index.values.IndexDocValues;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.PhraseQuery;
|
||||
import org.apache.lucene.store.AlreadyClosedException;
|
||||
|
@ -1212,5 +1214,48 @@ public class TestAddIndexes extends LuceneTestCase {
|
|||
}
|
||||
r3.close();
|
||||
d3.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testDocValues() throws IOException {
|
||||
assumeFalse("preflex does not support docvalues", Codec.getDefault().getName().equals("Lucene3x"));
|
||||
Directory d1 = newDirectory();
|
||||
RandomIndexWriter w = new RandomIndexWriter(random, d1);
|
||||
Document doc = new Document();
|
||||
doc.add(newField("id", "1", StringField.TYPE_STORED));
|
||||
IndexDocValuesField dv = new IndexDocValuesField("dv");
|
||||
dv.setInt(1);
|
||||
doc.add(dv);
|
||||
w.addDocument(doc);
|
||||
IndexReader r1 = w.getReader();
|
||||
w.close();
|
||||
|
||||
Directory d2 = newDirectory();
|
||||
w = new RandomIndexWriter(random, d2);
|
||||
doc = new Document();
|
||||
doc.add(newField("id", "2", StringField.TYPE_STORED));
|
||||
dv = new IndexDocValuesField("dv");
|
||||
dv.setInt(2);
|
||||
doc.add(dv);
|
||||
w.addDocument(doc);
|
||||
IndexReader r2 = w.getReader();
|
||||
w.close();
|
||||
|
||||
Directory d3 = newDirectory();
|
||||
w = new RandomIndexWriter(random, d3);
|
||||
w.addIndexes(new SlowMultiReaderWrapper(r1), new SlowMultiReaderWrapper(r2));
|
||||
r1.close();
|
||||
d1.close();
|
||||
r2.close();
|
||||
d2.close();
|
||||
|
||||
w.forceMerge(1);
|
||||
IndexReader r3 = w.getReader();
|
||||
w.close();
|
||||
IndexReader sr = getOnlySegmentReader(r3);
|
||||
assertEquals(2, sr.numDocs());
|
||||
IndexDocValues docValues = sr.perDocValues().docValues("dv");
|
||||
assertNotNull(docValues);
|
||||
r3.close();
|
||||
d3.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.lucene.index.IndexReader.ReaderContext;
|
|||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.NoMergePolicy;
|
||||
import org.apache.lucene.index.SlowMultiReaderWrapper;
|
||||
import org.apache.lucene.index.codecs.Codec;
|
||||
import org.apache.lucene.index.values.IndexDocValues.Source;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
@ -101,7 +102,9 @@ public class TestTypePromotion extends LuceneTestCase {
|
|||
} else {
|
||||
// do a real merge here
|
||||
IndexReader open = IndexReader.open(dir_2);
|
||||
writer.addIndexes(open);
|
||||
// we cannot use SlowMR for sorted bytes, because it returns a null sortedsource
|
||||
boolean useSlowMRWrapper = types != SORTED_BYTES && random.nextBoolean();
|
||||
writer.addIndexes(useSlowMRWrapper ? new SlowMultiReaderWrapper(open) : open);
|
||||
open.close();
|
||||
}
|
||||
dir_2.close();
|
||||
|
|
Loading…
Reference in New Issue