You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/09/04 16:06:58 UTC
svn commit: r1701272 - in /lucene/dev/branches/branch_5x: ./ lucene/
lucene/CHANGES.txt lucene/queries/
lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java
Author: jpountz
Date: Fri Sep 4 14:06:58 2015
New Revision: 1701272
URL: http://svn.apache.org/r1701272
Log:
LUCENE-6781: BoostingQuery implements rewrite().
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/lucene/ (props changed)
lucene/dev/branches/branch_5x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/lucene/queries/ (props changed)
lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java
Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1701272&r1=1701271&r2=1701272&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Fri Sep 4 14:06:58 2015
@@ -60,6 +60,8 @@ Bug Fixes
* LUCENE-6774: Remove classloader hack in MorfologikFilter. (Robert Muir,
Uwe Schindler)
+* LUCENE-6781: Fixed BoostingQuery to rewrite wrapped queries. (Adrien Grand)
+
Other
* LUCENE-6174: Improve "ant eclipse" to select right JRE for building.
Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java?rev=1701272&r1=1701271&r2=1701272&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java Fri Sep 4 14:06:58 2015
@@ -21,10 +21,10 @@ import java.io.IOException;
import java.util.Objects;
import java.util.Set;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
-import org.apache.lucene.util.Bits;
/**
* The BoostingQuery class can be used to effectively demote results that match a given query.
@@ -55,6 +55,18 @@ public class BoostingQuery extends Query
}
@Override
+ public Query rewrite(IndexReader reader) throws IOException {
+ Query matchRewritten = match.rewrite(reader);
+ Query contextRewritten = context.rewrite(reader);
+ if (match != matchRewritten || context != contextRewritten) {
+ BoostingQuery rewritten = new BoostingQuery(matchRewritten, contextRewritten, boost);
+ rewritten.setBoost(getBoost());
+ return rewritten;
+ }
+ return super.rewrite(reader);
+ }
+
+ @Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
if (needsScores == false) {
return match.createWeight(searcher, needsScores);
Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java?rev=1701272&r1=1701271&r2=1701272&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/BoostingQueryTest.java Fri Sep 4 14:06:58 2015
@@ -17,7 +17,15 @@ package org.apache.lucene.queries;
* limitations under the License.
*/
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.MultiReader;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.MatchNoDocsQuery;
+import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryUtils;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.LuceneTestCase;
@@ -35,4 +43,13 @@ public class BoostingQueryTest extends L
BoostingQuery bq2 = new BoostingQuery(q1, q2, 0.1f);
assertEquals("BoostingQuery with same attributes is not equal", bq1, bq2);
}
+
+ public void testRewrite() throws IOException {
+ IndexReader reader = new MultiReader();
+ BoostingQuery q = new BoostingQuery(new MatchNoDocsQuery(), new MatchAllDocsQuery(), 3);
+ Query rewritten = q.rewrite(reader);
+ Query expectedRewritten = new BoostingQuery(new BooleanQuery.Builder().build(), new MatchAllDocsQuery(), 3);
+ assertEquals(expectedRewritten, rewritten);
+ assertSame(rewritten, rewritten.rewrite(reader));
+ }
}