From 424369f49140e3a69e9784013f23e52b57c0be23 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 20 Aug 2013 02:46:13 +0000 Subject: [PATCH] add test git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5178@1515689 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/TestMultiDocValues.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java index 78c8974c555..8944dd66b67 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestMultiDocValues.java @@ -26,6 +26,7 @@ import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.SortedDocValuesField; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; @@ -321,4 +322,52 @@ public class TestMultiDocValues extends LuceneTestCase { ir2.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(); + } }