jpountz commented on code in PR #11722: URL: https://github.com/apache/lucene/pull/11722#discussion_r982050404
########## lucene/test-framework/src/java/org/apache/lucene/tests/index/BasePostingsFormatTestCase.java: ########## @@ -367,6 +367,53 @@ public void testGhosts() throws Exception { dir.close(); } + public void testBinarySearchTermLeaf() throws Exception { + Directory dir = newDirectory(); + + IndexWriterConfig iwc = newIndexWriterConfig(null); + iwc.setCodec(getCodec()); + iwc.setMergePolicy(newTieredMergePolicy()); + IndexWriter iw = new IndexWriter(dir, iwc); + + for (int i = 100000; i <= 100400; i++){ + // only add odd number + if (i % 2 == 1) { + Document document = new Document(); + document.add(new StringField("id", i + "", Field.Store.NO)); + iw.addDocument(document); + } + } + iw.commit(); + iw.forceMerge(1); + + DirectoryReader reader = DirectoryReader.open(iw); + TermsEnum termsEnum = getOnlyLeafReader(reader).terms("id").iterator(); + // test seekExact + for (int i = 100000; i <= 100400; i++){ + BytesRef target = new BytesRef(i + ""); + if (i % 2 == 1) { + assertTrue(termsEnum.seekExact(target)); + assertEquals(termsEnum.term(), target); + } else { + assertFalse(termsEnum.seekExact(target)); + } + } + // test seekCeil + for (int i = 100000; i < 100400; i++){ + BytesRef target = new BytesRef(i + ""); + if (i % 2 == 1) { + assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(target)); + assertEquals(termsEnum.term(), target); + } else { + assertEquals(SeekStatus.NOT_FOUND, termsEnum.seekCeil(target)); Review Comment: maybe also assert here that the terms enum is positioned on the next term? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org