From c947254a3dcecc2c61a337742ba344dc7e3b8fa9 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Wed, 26 Sep 2007 03:25:30 +0000 Subject: [PATCH] fix BoostedQuery.rewrite git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@579445 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/search/function/BoostedQuery.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/solr/search/function/BoostedQuery.java b/src/java/org/apache/solr/search/function/BoostedQuery.java index 8e0d9d2c8a2..8bf81384e22 100755 --- a/src/java/org/apache/solr/search/function/BoostedQuery.java +++ b/src/java/org/apache/solr/search/function/BoostedQuery.java @@ -40,7 +40,11 @@ public class BoostedQuery extends Query { public ValueSource getValueSource() { return boostVal; } public Query rewrite(IndexReader reader) throws IOException { - return q.rewrite(reader); + Query newQ = q.rewrite(reader); + if (newQ == q) return this; + BoostedQuery bq = (BoostedQuery)this.clone(); + bq.q = newQ; + return bq; } public void extractTerms(Set terms) { @@ -53,12 +57,11 @@ public class BoostedQuery extends Query { private class BoostedWeight implements Weight { Searcher searcher; - Weight weight; - boolean qStrict; + Weight qWeight; public BoostedWeight(Searcher searcher) throws IOException { this.searcher = searcher; - this.weight = q.weight(searcher); + this.qWeight = q.weight(searcher); } public Query getQuery() { @@ -70,18 +73,18 @@ public class BoostedQuery extends Query { } public float sumOfSquaredWeights() throws IOException { - float sum = weight.sumOfSquaredWeights(); + float sum = qWeight.sumOfSquaredWeights(); sum *= getBoost() * getBoost(); return sum ; } public void normalize(float norm) { norm *= getBoost(); - weight.normalize(norm); + qWeight.normalize(norm); } public Scorer scorer(IndexReader reader) throws IOException { - Scorer subQueryScorer = weight.scorer(reader); + Scorer subQueryScorer = qWeight.scorer(reader); return new BoostedQuery.CustomScorer(getSimilarity(searcher), reader, this, subQueryScorer, boostVal); } @@ -125,7 +128,7 @@ public class BoostedQuery extends Query { } public Explanation explain(int doc) throws IOException { - Explanation subQueryExpl = weight.weight.explain(reader,doc); + Explanation subQueryExpl = weight.qWeight.explain(reader,doc); if (!subQueryExpl.isMatch()) { return subQueryExpl; }