Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-3495: BlockJoinQuery doesnt implement boost, but other parts of lucene expect this works

Robert Muir026f36a7348d
diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txt
index 4ca4e758cd7..4bf28d4c009 100644
--- a/lucene/contrib/CHANGES.txt
+++ b/lucene/contrib/CHANGES.txt
@@ -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
diff --git a/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java b/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
index 96f620b809f..37dc1f92c5b 100644
--- a/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
+++ b/modules/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
@@ -138,12 +138,12 @@ public class BlockJoinQuery extends Query {
@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 Query {
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;
}
@@ -370,16 +372,6 @@ public class BlockJoinQuery extends Query {
return "BlockJoinQuery ("+childQuery.toString()+")";
}
- @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) {
diff --git a/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java b/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java
index 1229eecd41a..2551449c08c 100644
--- a/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java
+++ b/modules/join/src/test/org/apache/lucene/search/TestBlockJoin.java
@@ -122,6 +122,24 @@ public class TestBlockJoin extends LuceneTestCase {
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) {