Skip to content

Apache Lucene open-source search software

LUCENE-6271: add simple test

Robert Muir0b8e5fb822a5
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
index 171224bb9a0..6523e5502a8 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
@@ -1505,6 +1505,29 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest
dir.close();
}
+ public void testAskForPositionsWhenNotThere() throws Exception {
+ Directory dir = newDirectory();
+ IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+ iwc.setCodec(getCodec());
+ RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
+ Document doc = new Document();
+ doc.add(newStringField("field", "value", Field.Store.NO));
+ iw.addDocument(doc);
+ iw.addDocument(doc);
+ DirectoryReader ir = iw.getReader();
+ LeafReader ar = getOnlySegmentReader(ir);
+ TermsEnum termsEnum = ar.terms("field").iterator(null);
+ assertTrue(termsEnum.seekExact(new BytesRef("value")));
+ PostingsEnum docsEnum = termsEnum.postings(null, null, PostingsEnum.POSITIONS);
+ assertEquals(0, docsEnum.nextDoc());
+ assertEquals(1, docsEnum.freq());
+ assertEquals(1, docsEnum.nextDoc());
+ assertEquals(1, docsEnum.freq());
+ ir.close();
+ iw.close();
+ dir.close();
+ }
+
// tests that ghost fields still work
// TODO: can this be improved?
public void testGhosts() throws Exception {