You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/10/06 20:52:37 UTC
svn commit: r1179762 - in /lucene/dev/trunk: lucene/contrib/CHANGES.txt
modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java
Author: rmuir
Date: Thu Oct 6 18:52:37 2011
New Revision: 1179762
URL: http://svn.apache.org/viewvc?rev=1179762&view=rev
Log:
LUCENE-3495: BlockJoinQuery doesnt implement boost, but other parts of lucene expect this works
Modified:
lucene/dev/trunk/lucene/contrib/CHANGES.txt
lucene/dev/trunk/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
lucene/dev/trunk/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java
Modified: lucene/dev/trunk/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/CHANGES.txt?rev=1179762&r1=1179761&r2=1179762&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/contrib/CHANGES.txt Thu Oct 6 18:52:37 2011
@@ -112,6 +112,9 @@ Bug Fixes
* LUCENE-3484: Fix NPE in TaxonomyWriter: parents array creation was not thread safe.
(Doron Cohen)
+
+ * LUCENE-3495: Fix BlockJoinQuery to properly implement getBoost()/setBoost().
+ (Robert Muir)
API Changes
Modified: lucene/dev/trunk/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java?rev=1179762&r1=1179761&r2=1179762&view=diff
==============================================================================
--- lucene/dev/trunk/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java (original)
+++ lucene/dev/trunk/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java Thu Oct 6 18:52:37 2011
@@ -138,12 +138,12 @@ public class BlockJoinQuery extends Quer
@Override
public float getValueForNormalization() throws IOException {
- return childWeight.getValueForNormalization();
+ return childWeight.getValueForNormalization() * joinQuery.getBoost() * joinQuery.getBoost();
}
@Override
public void normalize(float norm, float topLevelBoost) {
- childWeight.normalize(norm, topLevelBoost);
+ childWeight.normalize(norm, topLevelBoost * joinQuery.getBoost());
}
@Override
@@ -356,10 +356,12 @@ public class BlockJoinQuery extends Quer
public Query rewrite(IndexReader reader) throws IOException {
final Query childRewrite = childQuery.rewrite(reader);
if (childRewrite != childQuery) {
- return new BlockJoinQuery(childQuery,
+ Query rewritten = new BlockJoinQuery(childQuery,
childRewrite,
parentsFilter,
scoreMode);
+ rewritten.setBoost(getBoost());
+ return rewritten;
} else {
return this;
}
@@ -371,16 +373,6 @@ public class BlockJoinQuery extends Quer
}
@Override
- public void setBoost(float boost) {
- throw new UnsupportedOperationException("this query cannot support boosting; please use childQuery.setBoost instead");
- }
-
- @Override
- public float getBoost() {
- throw new UnsupportedOperationException("this query cannot support boosting; please use childQuery.getBoost instead");
- }
-
- @Override
public boolean equals(Object _other) {
if (_other instanceof BlockJoinQuery) {
final BlockJoinQuery other = (BlockJoinQuery) _other;
Modified: lucene/dev/trunk/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java?rev=1179762&r1=1179761&r2=1179762&view=diff
==============================================================================
--- lucene/dev/trunk/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java (original)
+++ lucene/dev/trunk/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java Thu Oct 6 18:52:37 2011
@@ -122,6 +122,24 @@ public class TestBlockJoin extends Lucen
r.close();
dir.close();
}
+
+ public void testBoostBug() throws Exception {
+ final Directory dir = newDirectory();
+ final RandomIndexWriter w = new RandomIndexWriter(random, dir);
+ IndexReader r = w.getReader();
+ w.close();
+ IndexSearcher s = newSearcher(r);
+
+ BlockJoinQuery q = new BlockJoinQuery(new MatchAllDocsQuery(), new QueryWrapperFilter(new MatchAllDocsQuery()), BlockJoinQuery.ScoreMode.Avg);
+ s.search(q, 10);
+ BooleanQuery bq = new BooleanQuery();
+ bq.setBoost(2f); // we boost the BQ
+ bq.add(q, BooleanClause.Occur.MUST);
+ s.search(bq, 10);
+ s.close();
+ r.close();
+ dir.close();
+ }
private String[][] getRandomFields(int maxUniqueValues) {