Index: lucene/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java =================================================================== --- lucene/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java (revision 1056691) +++ lucene/contrib/queries/src/java/org/apache/lucene/search/FuzzyLikeThisQuery.java (working copy) @@ -292,7 +292,7 @@ { //optimize where only one selected variant ScoreTerm st= variants.get(0); - TermQuery tq = new FuzzyTermQuery(st.term,ignoreTF); + Query tq = ignoreTF ? new ConstantScoreQuery(new TermQuery(st.term)) : new TermQuery(st.term, 1); tq.setBoost(st.score); // set the boost to a mix of IDF and score bq.add(tq, BooleanClause.Occur.SHOULD); } @@ -303,7 +303,8 @@ .hasNext();) { ScoreTerm st = iterator2.next(); - TermQuery tq = new FuzzyTermQuery(st.term,ignoreTF); // found a match + // found a match + Query tq = ignoreTF ? new ConstantScoreQuery(new TermQuery(st.term)) : new TermQuery(st.term, 1); tq.setBoost(st.score); // set the boost using the ScoreTerm's score termVariants.add(tq, BooleanClause.Occur.SHOULD); // add to query } @@ -348,45 +349,8 @@ return termA.score < termB.score; } - } + } - //overrides basic TermQuery to negate effects of IDF (idf is factored into boost of containing BooleanQuery) - private static class FuzzyTermQuery extends TermQuery - { - boolean ignoreTF; - public FuzzyTermQuery(Term t, boolean ignoreTF) - { - super(t); - this.ignoreTF=ignoreTF; - } - @Override - public Similarity getSimilarity(IndexSearcher searcher) - { - Similarity result = super.getSimilarity(searcher); - result = new SimilarityDelegator(result) { - - @Override - public float tf(float freq) - { - if(ignoreTF) - { - return 1; //ignore tf - } - return super.tf(freq); - } - @Override - public float idf(int docFreq, int numDocs) - { - //IDF is already factored into individual term boosts - return 1; - } - }; - return result; - } - } - - - /* (non-Javadoc) * @see org.apache.lucene.search.Query#toString(java.lang.String) */