mirror of https://github.com/apache/lucene.git
add test
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5178@1515689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cf0078a686
commit
424369f491
|
@ -26,6 +26,7 @@ import org.apache.lucene.document.NumericDocValuesField;
|
||||||
import org.apache.lucene.document.SortedDocValuesField;
|
import org.apache.lucene.document.SortedDocValuesField;
|
||||||
import org.apache.lucene.document.SortedSetDocValuesField;
|
import org.apache.lucene.document.SortedSetDocValuesField;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util._TestUtil;
|
import org.apache.lucene.util._TestUtil;
|
||||||
|
@ -321,4 +322,52 @@ public class TestMultiDocValues extends LuceneTestCase {
|
||||||
ir2.close();
|
ir2.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDocsWithField() throws Exception {
|
||||||
|
assumeTrue("codec does not support docsWithField", defaultCodecSupportsDocsWithField());
|
||||||
|
Directory dir = newDirectory();
|
||||||
|
|
||||||
|
IndexWriterConfig iwc = newIndexWriterConfig(random(), TEST_VERSION_CURRENT, null);
|
||||||
|
iwc.setMergePolicy(newLogMergePolicy());
|
||||||
|
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
|
||||||
|
|
||||||
|
int numDocs = atLeast(500);
|
||||||
|
for (int i = 0; i < numDocs; i++) {
|
||||||
|
Document doc = new Document();
|
||||||
|
if (random().nextInt(4) >= 0) {
|
||||||
|
doc.add(new NumericDocValuesField("numbers", random().nextLong()));
|
||||||
|
}
|
||||||
|
doc.add(new NumericDocValuesField("numbersAlways", random().nextLong()));
|
||||||
|
iw.addDocument(doc);
|
||||||
|
if (random().nextInt(17) == 0) {
|
||||||
|
iw.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DirectoryReader ir = iw.getReader();
|
||||||
|
iw.forceMerge(1);
|
||||||
|
DirectoryReader ir2 = iw.getReader();
|
||||||
|
AtomicReader merged = getOnlySegmentReader(ir2);
|
||||||
|
iw.close();
|
||||||
|
|
||||||
|
Bits multi = MultiDocValues.getDocsWithField(ir, "numbers");
|
||||||
|
Bits single = merged.getDocsWithField("numbers");
|
||||||
|
if (multi == null) {
|
||||||
|
assertNull(single);
|
||||||
|
} else {
|
||||||
|
assertEquals(single.length(), multi.length());
|
||||||
|
for (int i = 0; i < numDocs; i++) {
|
||||||
|
assertEquals(single.get(i), multi.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
multi = MultiDocValues.getDocsWithField(ir, "numbersAlways");
|
||||||
|
single = merged.getDocsWithField("numbersAlways");
|
||||||
|
assertEquals(single.length(), multi.length());
|
||||||
|
for (int i = 0; i < numDocs; i++) {
|
||||||
|
assertEquals(single.get(i), multi.get(i));
|
||||||
|
}
|
||||||
|
ir.close();
|
||||||
|
ir2.close();
|
||||||
|
dir.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue