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:58:02 UTC

svn commit: r1179768 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/src/test/ lucene/contrib/ lucene/contrib/join/src/java/org/apache/lucene/search/join/ lucene/contrib/join/src/test/org/apache/lucene/search/ solr/

Author: rmuir
Date: Thu Oct  6 18:58:01 2011
New Revision: 1179768

URL: http://svn.apache.org/viewvc?rev=1179768&view=rev
Log:
LUCENE-3495: BlockJoinQuery doesnt implement boost, but other parts of lucene expect this works

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt
    lucene/dev/branches/branch_3x/lucene/contrib/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
    lucene/dev/branches/branch_3x/lucene/contrib/join/src/test/org/apache/lucene/search/TestBlockJoin.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt?rev=1179768&r1=1179767&r2=1179768&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt Thu Oct  6 18:58:01 2011
@@ -58,6 +58,9 @@ Bug Fixes
  * LUCENE-3485: Fix a bug in LuceneTaxonomyReader, where calling decRef() might
    close the inner IndexReader, leaving the taxonomy reader in limbo.
    (Gilad Barkai via Shai Erera)
+   
+ * LUCENE-3495: Fix BlockJoinQuery to properly implement getBoost()/setBoost().
+   (Robert Muir)
 
 API Changes
  

Modified: lucene/dev/branches/branch_3x/lucene/contrib/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java?rev=1179768&r1=1179767&r2=1179768&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/join/src/java/org/apache/lucene/search/join/BlockJoinQuery.java Thu Oct  6 18:58:01 2011
@@ -138,12 +138,12 @@ public class BlockJoinQuery extends Quer
 
     @Override
     public float sumOfSquaredWeights() throws IOException {
-      return childWeight.sumOfSquaredWeights();
+      return childWeight.sumOfSquaredWeights() * joinQuery.getBoost() * joinQuery.getBoost();
     }
 
     @Override
     public void normalize(float norm) {
-      childWeight.normalize(norm);
+      childWeight.normalize(norm * joinQuery.getBoost());
     }
 
     @Override
@@ -358,10 +358,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;
     }
@@ -373,16 +375,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/branches/branch_3x/lucene/contrib/join/src/test/org/apache/lucene/search/TestBlockJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/join/src/test/org/apache/lucene/search/TestBlockJoin.java?rev=1179768&r1=1179767&r2=1179768&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/join/src/test/org/apache/lucene/search/TestBlockJoin.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/join/src/test/org/apache/lucene/search/TestBlockJoin.java Thu Oct  6 18:58:01 2011
@@ -121,6 +121,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) {