Buggy code:
sortFields . add ( new SortField ( "string" , SortField . STRING , false ) ) ; sortFields . add ( new SortField ( "int" , SortField . INT , true ) ) ; sortFields . add ( new SortField ( "int" , SortField . INT , false ) ) ; sortFields . add ( new SortField ( "float" , SortField . FLOAT , true ) ) ; sortFields . add ( new SortField ( "float" , SortField . FLOAT , false ) ) ; sortFields . add ( new SortField ( null , SortField . SCORE , true ) ) ; sortFields . add ( new SortField ( null , SortField . SCORE , false ) ) ; sortFields . add ( new SortField ( null , SortField . DOC , true ) ) ; sortFields . add ( new SortField ( null , SortField . DOC , false ) ) ; final int [ ] docStarts = new int [ subSearchers . length ] ; int docBase = 0 ; for ( int subIDX = 0 ; subIDX < ( docStarts . length ) ; subIDX ++ ) { docStarts [ subIDX ] = docBase ; docBase += subReaders [ subIDX ] . maxDoc ( ) ; if ( VERBOSE ) { System . out . println ( ( ( ( "docStarts[" + subIDX ) + "]=" ) + ( docStarts [ subIDX ] ) ) ) ; } } for ( int iter = 0 ; iter < ( 1000 * ( RANDOM_MULTIPLIER ) ) ; iter ++ ) { final Query query = new TermQuery ( new Term ( "text" , tokens [ random . nextInt ( tokens . length ) ] ) ) ; final Sort sort ; if ( ( random . nextInt ( 10 ) ) == 4 ) { sort = null ; } else { final SortField [ ] randomSortFields = new SortField [ _TestUtil . nextInt ( random , 1 , 3 ) ] ; for ( int sortIDX = 0 ; sortIDX < ( randomSortFields . length ) ; sortIDX ++ ) { randomSortFields [ sortIDX ] = sortFields . get ( random . nextInt ( sortFields . size ( ) ) ) ; } sort = new Sort ( randomSortFields ) ; } final int numHits = _TestUtil . nextInt ( random , 1 , ( numDocs + 5 ) ) ; if ( VERBOSE ) { System . out . println ( ( ( ( ( ( "TEST:<seq2seq4repair_space>search<seq2seq4repair_space>query=" + query ) + "<seq2seq4repair_space>sort=" ) + sort ) + "<seq2seq4repair_space>numHits=" ) + numHits ) ) ; } final TopDocs topHits ; if ( sort == null ) { topHits = searcher . search ( query , numHits ) ; } else { final TopFieldCollector c = TopFieldCollector . create ( sort , numHits , true , true , true , random . nextBoolean ( ) ) ; searcher . search ( query , c ) ; topHits = c . topDocs ( 0 , numHits ) ; } if ( VERBOSE ) { System . out . println ( ( ( ( "<seq2seq4repair_space>top<seq2seq4repair_space>search:<seq2seq4repair_space>" + ( topHits . totalHits ) ) + "<seq2seq4repair_space>totalHits;<seq2seq4repair_space>hits=" ) + ( ( topHits . scoreDocs ) == null ? "null" : topHits . scoreDocs . length ) ) ) ; if ( ( topHits . scoreDocs ) != null ) { for ( int hitIDX = 0 ; hitIDX < ( topHits . scoreDocs . length ) ; hitIDX ++ ) { final ScoreDoc sd = topHits . scoreDocs [ hitIDX ] ; System . out . println ( ( ( ( "<seq2seq4repair_space>doc=" + ( sd . doc ) ) + "<seq2seq4repair_space>score=" ) + ( sd . score ) ) ) ; } } } <START_BUG> final Weight w = query . weight ( searcher ) ; <END_BUG> final TopDocs [ ] shardHits = new TopDocs [ subSearchers . length ] ; for ( int shardIDX = 0 ; shardIDX < ( subSearchers . length ) ; shardIDX ++ ) { final TopDocs subHits ; final TestTopDocsMerge . ShardSearcher subSearcher = subSearchers [ shardIDX ] ; if ( sort == null ) { subHits = subSearcher . search ( w , numHits ) ; } else { final TopFieldCollector c = TopFieldCollector . create ( sort , numHits , true , true , true , random . nextBoolean ( ) ) ; subSearcher . search ( w , c ) ; subHits = c . topDocs ( 0 , numHits ) ; } rebaseDocIDs ( docStarts [ shardIDX ] , subHits ) ; shardHits [ shardIDX ] = subHits ; if ( VERBOSE ) { System . out . println ( ( ( ( ( ( "<seq2seq4repair_space>shard=" + shardIDX ) + "<seq2seq4repair_space>" ) + ( subHits . totalHits ) ) + "<seq2seq4repair_space>totalHits<seq2seq4repair_space>hits=" ) + ( ( subHits . scoreDocs ) == null ? "null" : subHits . scoreDocs . length ) ) ) ; if ( ( subHits . scoreDocs ) != null ) { for ( ScoreDoc sd : subHits . scoreDocs ) { System . out . println ( ( ( ( "<seq2seq4repair_space>doc=" + ( sd . doc ) ) + "<seq2seq4repair_space>score=" ) + ( sd . score ) ) ) ; } } } } final TopDocs mergedHits = TopDocs . merge ( sort , numHits , shardHits ) ; if ( VERBOSE ) { System . out . println ( ( ( ( "<seq2seq4repair_space>mergedHits:<seq2seq4repair_space>" + ( mergedHits . totalHits ) ) + "<seq2seq4repair_space>totalHits;<seq2seq4repair_space>hits=" ) + ( ( mergedHits . scoreDocs ) == null ? "null" : mergedHits . scoreDocs . length ) ) ) ; if ( ( mergedHits . scoreDocs ) != null ) { for ( int hitIDX = 0 ; hitIDX < ( mergedHits . scoreDocs . length ) ; hitIDX ++ ) { final ScoreDoc sd = mergedHits . scoreDocs [ hitIDX ] ;

Fix:
final Weight w = searcher . createNormalizedWeight ( query ) ;