mirror of https://github.com/apache/lucene.git
LUCENE-3495: BlockJoinQuery doesnt implement boost, but other parts of lucene expect this works
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1179762 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2d5a528464
commit
026f36a734
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue