Buggy code:
public class TestSimilarity extends LuceneTestCase { public TestSimilarity ( String name ) { } 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 testSimilarity ( ) throws Exception { RAMDirectory store = new RAMDirectory ( ) ; IndexWriter writer = new IndexWriter ( store , new SimpleAnalyzer ( ) , true , MaxFieldLength . LIMITED ) ; writer . setSimilarity ( new TestSimilarity . SimpleSimilarity ( ) ) ; Document d1 = new Document ( ) ; d1 . add ( new org . apache . lucene . document . Field ( "field" , "a<seq2seq4repair_space>c" , Store . YES , Index . ANALYZED ) ) ; Document d2 = new Document ( ) ; d2 . add ( new org . apache . lucene . document . Field ( "field" , "a<seq2seq4repair_space>b<seq2seq4repair_space>c" , Store . YES , Index . ANALYZED ) ) ; writer . addDocument ( d1 ) ; writer . addDocument ( d2 ) ; writer . optimize ( ) ; writer . close ( ) ; <START_BUG> Searcher searcher = new IndexSearcher ( store ) ; <END_BUG> searcher . setSimilarity ( new TestSimilarity . SimpleSimilarity ( ) ) ; Term a = new Term ( "field" , "a" ) ; Term b = new Term ( "field" , "b" ) ; Term c = new Term ( "field" , "c" ) ; searcher . search ( new TermQuery ( b ) , new Collector ( ) { private Scorer scorer ; public void setScorer ( Scorer scorer ) throws IOException { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { assertTrue ( ( ( scorer . score ( ) ) == 1.0F ) ) ; } public void setNextReader ( IndexReader reader , int docBase ) { } public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; BooleanQuery bq = new BooleanQuery ( ) ; bq . add ( new TermQuery ( a ) , SHOULD ) ; bq . add ( new TermQuery ( b ) , SHOULD ) ; searcher . search ( bq , new Collector ( ) { private int base = 0 ; private Scorer scorer ; public void setScorer ( Scorer scorer ) throws IOException { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { assertTrue ( ( ( scorer . score ( ) ) == ( ( ( ( float ) ( doc ) ) + ( base ) ) + 1 ) ) ) ; } public void setNextReader ( IndexReader reader , int docBase ) { base = docBase ; } public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; PhraseQuery pq = new PhraseQuery ( ) ; pq . add ( a ) ; pq . add ( c ) ; searcher . search ( pq , new Collector ( ) { private Scorer scorer ; public void setScorer ( Scorer scorer ) throws IOException { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { assertTrue ( ( ( scorer . score ( ) ) == 1.0F ) ) ; } public void setNextReader ( IndexReader reader , int docBase ) { } public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; pq . setSlop ( 2 ) ; searcher . search ( pq , new Collector ( ) { private Scorer scorer ; public void setScorer ( Scorer scorer ) throws IOException { this . scorer = scorer ; } public final void collect ( int doc ) throws IOException { assertTrue ( ( ( scorer . score ( ) ) == 2.0F ) ) ; } public void setNextReader ( IndexReader reader , int docBase ) { } public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; } }

Fix:
Searcher searcher = new IndexSearcher ( store , true ) ;