Buggy code:
public class TestOmitTf extends LuceneTestCase { public static class SimpleSimilarity extends Similarity { public float lengthNorm ( String field , int numTerms ) { } public float queryNorm ( float sumOfSquaredWeights ) { } public float tf ( float freq ) { } public float sloppyFreq ( int distance ) { } public float idf ( Collection terms , Searcher searcher ) { } public float idf ( int docFreq , int numDocs ) { } public float coord ( int overlap , int maxOverlap ) { } } public void testOmitTermFreqAndPositions ( ) throws Exception { } public void testMixedMerge ( ) throws Exception { } public void testMixedRAM ( ) throws Exception { } private void assertNoPrx ( Directory dir ) throws Throwable { } public void testNoPrxFile ( ) throws Throwable { } public void testBasic ( ) throws Exception { Directory dir = new MockRAMDirectory ( ) ; Analyzer analyzer = new StandardAnalyzer ( ) ; IndexWriter writer = new IndexWriter ( dir , analyzer , true , MaxFieldLength . LIMITED ) ; writer . setMergeFactor ( 2 ) ; writer . setMaxBufferedDocs ( 2 ) ; writer . setSimilarity ( new TestOmitTf . SimpleSimilarity ( ) ) ; StringBuffer sb = new StringBuffer ( 265 ) ; String term = "term" ; for ( int i = 0 ; i < 30 ; i ++ ) { Document d = new Document ( ) ; sb . append ( term ) . append ( "<seq2seq4repair_space>" ) ; String content = sb . toString ( ) ; Field noTf = new Field ( "noTf" , ( content + ( ( i % 2 ) == 0 ? "" : "<seq2seq4repair_space>notf" ) ) , Store . NO , Index . ANALYZED ) ; noTf . setOmitTermFreqAndPositions ( true ) ; d . add ( noTf ) ; Field tf = new Field ( "tf" , ( content + ( ( i % 2 ) == 0 ? "<seq2seq4repair_space>tf" : "" ) ) , Store . NO , Index . ANALYZED ) ; d . add ( tf ) ; writer . addDocument ( d ) ; } writer . optimize ( ) ; writer . close ( ) ; _TestUtil . checkIndex ( dir ) ; <START_BUG> Searcher searcher = new org . apache . lucene . search . IndexSearcher ( dir ) ; <END_BUG> searcher . setSimilarity ( new TestOmitTf . SimpleSimilarity ( ) ) ; Term a = new Term ( "noTf" , term ) ; Term b = new Term ( "tf" , term ) ; Term c = new Term ( "noTf" , "notf" ) ; Term d = new Term ( "tf" , "tf" ) ; TermQuery q1 = new TermQuery ( a ) ; TermQuery q2 = new TermQuery ( b ) ; TermQuery q3 = new TermQuery ( c ) ; TermQuery q4 = new TermQuery ( d ) ; searcher . search ( q1 , new TestOmitTf . CountingHitCollector ( ) { private Scorer scorer ; public final void setScorer ( Scorer scorer ) { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { float score = scorer . score ( ) ; assertTrue ( ( score == 1.0F ) ) ; super . collect ( doc ) ; } } ) ; searcher . search ( q2 , new TestOmitTf . CountingHitCollector ( ) { private Scorer scorer ; public final void setScorer ( Scorer scorer ) { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { float score = scorer . score ( ) ; assertTrue ( ( score == ( 1.0F + doc ) ) ) ; super . collect ( doc ) ; } } ) ; searcher . search ( q3 , new TestOmitTf . CountingHitCollector ( ) { private Scorer scorer ; public final void setScorer ( Scorer scorer ) { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { float score = scorer . score ( ) ; assertTrue ( ( score == 1.0F ) ) ; assertFalse ( ( ( doc % 2 ) == 0 ) ) ; super . collect ( doc ) ; } } ) ; searcher . search ( q4 , new TestOmitTf . CountingHitCollector ( ) { private Scorer scorer ; public final void setScorer ( Scorer scorer ) { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { float score = scorer . score ( ) ; assertTrue ( ( score == 1.0F ) ) ; assertTrue ( ( ( doc % 2 ) == 0 ) ) ; super . collect ( doc ) ; } } ) ; BooleanQuery bq = new BooleanQuery ( ) ; bq . add ( q1 , MUST ) ; bq . add ( q4 , MUST ) ; searcher . search ( bq , new TestOmitTf . CountingHitCollector ( ) { public final void collect ( int doc ) throws IOException { super . collect ( doc ) ; } } ) ; assertTrue ( ( 15 == ( TestOmitTf . CountingHitCollector . getCount ( ) ) ) ) ; searcher . close ( ) ; dir . close ( ) ; } public static class CountingHitCollector extends Collector { static int count = 0 ; static int sum = 0 ; private int docBase = - 1 ; CountingHitCollector ( ) { } public void setScorer ( Scorer scorer ) throws IOException { } public void collect ( int doc ) throws IOException { } public static int getCount ( ) { } public static int getSum ( ) { } public void setNextReader ( IndexReader reader , int docBase ) { } public boolean acceptsDocsOutOfOrder ( ) { } } }

Fix:
Searcher searcher = new org . apache . lucene . search . IndexSearcher ( dir , true ) ;