Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-6783: Removed side effects from FuzzyLikeThisQuery.rewrite.

Adrien Grandf92df1c93b9e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 783023158cb..9cb21392e65 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -115,6 +115,9 @@ Bug Fixes
* LUCENE-6781: Fixed BoostingQuery to rewrite wrapped queries. (Adrien Grand)
+* LUCENE-6783: Removed side effects from FuzzyLikeThisQuery.rewrite.
+ (Adrien Grand)
+
Other
* LUCENE-6174: Improve "ant eclipse" to select right JRE for building.
diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/FuzzyLikeThisQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/FuzzyLikeThisQuery.java
index 0d32a82ef67..434bfd7ff4f 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/FuzzyLikeThisQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/FuzzyLikeThisQuery.java
@@ -69,11 +69,9 @@ public class FuzzyLikeThisQuery extends Query
// the rewrite method can 'average' the TermContext's term statistics (docfreq,totalTermFreq)
// provided to TermQuery, so that the general idea is agnostic to any scoring system...
static TFIDFSimilarity sim=new DefaultSimilarity();
- Query rewrittenQuery=null;
ArrayList<FieldVals> fieldVals=new ArrayList<>();
Analyzer analyzer;
-
- ScoreTermQueue q;
+
int MAX_VARIANTS_PER_TERM=50;
boolean ignoreTF=false;
private int maxNumTerms;
@@ -126,7 +124,6 @@ public class FuzzyLikeThisQuery extends Query
*/
public FuzzyLikeThisQuery(int maxNumTerms, Analyzer analyzer)
{
- q=new ScoreTermQueue(maxNumTerms);
this.analyzer=analyzer;
this.maxNumTerms = maxNumTerms;
}
@@ -201,7 +198,7 @@ public class FuzzyLikeThisQuery extends Query
}
- private void addTerms(IndexReader reader, FieldVals f) throws IOException {
+ private void addTerms(IndexReader reader, FieldVals f, ScoreTermQueue q) throws IOException {
if (f.queryString == null) return;
final Terms terms = MultiFields.getTerms(reader, f.fieldName);
if (terms == null) {
@@ -290,20 +287,13 @@ public class FuzzyLikeThisQuery extends Query
@Override
public Query rewrite(IndexReader reader) throws IOException
{
- if(rewrittenQuery!=null)
- {
- return rewrittenQuery;
- }
+ ScoreTermQueue q = new ScoreTermQueue(maxNumTerms);
//load up the list of possible terms
- for (Iterator<FieldVals> iter = fieldVals.iterator(); iter.hasNext(); ) {
- FieldVals f = iter.next();
- addTerms(reader, f);
+ for (FieldVals f : fieldVals) {
+ addTerms(reader, f, q);
}
- //clear the list of fields
- fieldVals.clear();
-
- BooleanQuery.Builder bq=new BooleanQuery.Builder();
+ BooleanQuery.Builder bq = new BooleanQuery.Builder();
//create BooleanQueries to hold the variants for each token/field pair and ensure it
// has no coord factor
@@ -351,9 +341,7 @@ public class FuzzyLikeThisQuery extends Query
}
//TODO possible alternative step 3 - organize above booleans into a new layer of field-based
// booleans with a minimum-should-match of NumFields-1?
- Query q = bq.build();
- this.rewrittenQuery=q;
- return q;
+ return bq.build();
}
//Holds info for a fuzzy term variant - initially score is set to edit distance (for ranking best