Buggy code:
public class FuzzyLikeThisQuery extends Query { static TFIDFSimilarity sim = new DefaultSimilarity ( ) ; Query rewrittenQuery = null ; ArrayList < FuzzyLikeThisQuery . FieldVals > fieldVals = new ArrayList < FuzzyLikeThisQuery . FieldVals > ( ) ; Analyzer analyzer ; FuzzyLikeThisQuery . ScoreTermQueue q ; int MAX_VARIANTS_PER_TERM = 50 ; boolean ignoreTF = false ; private int maxNumTerms ; @ Override public int hashCode ( ) { } @ Override public boolean equals ( Object obj ) { } public FuzzyLikeThisQuery ( int maxNumTerms , Analyzer analyzer ) { } class FieldVals { String queryString ; String fieldName ; float minSimilarity ; int prefixLength ; public FieldVals ( String name , float similarity , int length , String queryString ) { } @ Override public int hashCode ( ) { } @ Override public boolean equals ( Object obj ) { } } public void addTerms ( String queryString , String fieldName , float minSimilarity , int prefixLength ) { } private void addTerms ( IndexReader reader , FuzzyLikeThisQuery . FieldVals f ) throws IOException { if ( ( f . queryString ) == null ) return ; TokenStream ts = analyzer . tokenStream ( f . fieldName , new StringReader ( f . queryString ) ) ; CharTermAttribute termAtt = ts . addAttribute ( CharTermAttribute . class ) ; int corpusNumDocs = reader . numDocs ( ) ; HashSet < String > processedTerms = new HashSet < String > ( ) ; ts . reset ( ) ; while ( ts . incrementToken ( ) ) { String term = termAtt . toString ( ) ; if ( ! ( processedTerms . contains ( term ) ) ) { processedTerms . add ( term ) ; FuzzyLikeThisQuery . ScoreTermQueue variantsQ = new FuzzyLikeThisQuery . ScoreTermQueue ( MAX_VARIANTS_PER_TERM ) ; float minScore = 0 ; Term startTerm = new Term ( f . fieldName , term ) ; AttributeSource atts = new AttributeSource ( ) ; MaxNonCompetitiveBoostAttribute maxBoostAtt = atts . addAttribute ( MaxNonCompetitiveBoostAttribute . class ) ; FuzzyTermsEnum fe = new FuzzyTermsEnum ( MultiFields . getTerms ( reader , startTerm . field ( ) ) , atts , startTerm , f . minSimilarity , f . prefixLength ) ; int df = reader . docFreq ( startTerm ) ; int numVariants = 0 ; int totalVariantDocFreqs = 0 ; BytesRef possibleMatch ; BoostAttribute boostAtt = fe . attributes ( ) . addAttribute ( BoostAttribute . class ) ; while ( ( possibleMatch = fe . next ( ) ) != null ) { numVariants ++ ; totalVariantDocFreqs += fe . docFreq ( ) ; float score = boostAtt . getBoost ( ) ; if ( ( ( variantsQ . size ( ) ) < ( MAX_VARIANTS_PER_TERM ) ) || ( score > minScore ) ) { <START_BUG> FuzzyLikeThisQuery . ScoreTerm st = new FuzzyLikeThisQuery . ScoreTerm ( new Term ( startTerm . field ( ) , new BytesRef ( possibleMatch ) ) , score , startTerm ) ; <END_BUG> variantsQ . insertWithOverflow ( st ) ; minScore = variantsQ . top ( ) . score ; } maxBoostAtt . setMaxNonCompetitiveBoost ( ( ( variantsQ . size ( ) ) >= ( MAX_VARIANTS_PER_TERM ) ? minScore : Float . NEGATIVE_INFINITY ) ) ; } if ( numVariants > 0 ) { int avgDf = totalVariantDocFreqs // numVariants ; if ( df == 0 ) { df = avgDf ; } int size = variantsQ . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { FuzzyLikeThisQuery . ScoreTerm st = variantsQ . pop ( ) ; st . score = ( ( st . score ) * ( st . score ) ) * ( FuzzyLikeThisQuery . sim . idf ( df , corpusNumDocs ) ) ; q . insertWithOverflow ( st ) ; } } } } ts . end ( ) ; ts . close ( ) ; } @ Override public Query rewrite ( IndexReader reader ) throws IOException { } private static class ScoreTerm { public Term term ; public float score ; Term fuzziedSourceTerm ; public ScoreTerm ( Term term , float score , Term fuzziedSourceTerm ) { } } private static class ScoreTermQueue extends PriorityQueue < FuzzyLikeThisQuery . ScoreTerm > { public ScoreTermQueue ( int size ) { } @ Override protected boolean lessThan ( FuzzyLikeThisQuery . ScoreTerm termA , FuzzyLikeThisQuery . ScoreTerm termB ) { } } @ Override public String toString ( String field ) { } public boolean isIgnoreTF ( ) { } public void setIgnoreTF ( boolean ignoreTF ) { } }

Fix:
FuzzyLikeThisQuery . ScoreTerm st = new FuzzyLikeThisQuery . ScoreTerm ( new Term ( startTerm . field ( ) , BytesRef . deepCopyOf ( possibleMatch ) ) , score , startTerm ) ;