jpountz commented on code in PR #11722: URL: https://github.com/apache/lucene/pull/11722#discussion_r981512784
########## lucene/test-framework/src/java/org/apache/lucene/tests/index/BasePostingsFormatTestCase.java: ########## @@ -367,6 +367,49 @@ 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++){ + if (i % 2 == 1) { + assertTrue(termsEnum.seekExact(new BytesRef(i + ""))); Review Comment: maybe assert that the value of `termsEnum.term()` is correct after this call ########## lucene/test-framework/src/java/org/apache/lucene/tests/index/BasePostingsFormatTestCase.java: ########## @@ -367,6 +367,49 @@ 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++){ + if (i % 2 == 1) { + assertTrue(termsEnum.seekExact(new BytesRef(i + ""))); + } else { + assertFalse(termsEnum.seekExact(new BytesRef(i + ""))); + } + } + // test seekCeil + for (int i = 100000; i < 100400; i++){ + if (i % 2 == 1) { + assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef(i + ""))); Review Comment: maybe assert that the value of `termsEnum.term()` is correct after this call -- 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