mirror of https://github.com/apache/lucene.git
LUCENE-7486: DisjunctionMaxQuery does not work correctly with queries that return negative scores
This commit is contained in:
parent
2bbca4c512
commit
d25aba2336
|
@ -70,6 +70,9 @@ Bug Fixes
|
|||
* LUCENE-7476: JapaneseNumberFilter should not invoke incrementToken
|
||||
on its input after it's exhausted (Andy Hind via Mike McCandless)
|
||||
|
||||
* LUCENE-7486: DisjunctionMaxQuery does not work correctly with queries that
|
||||
return negative scores. (Ivan Provalov, Uwe Schindler, Adrien Grand)
|
||||
|
||||
Improvements
|
||||
|
||||
* LUCENE-7439: FuzzyQuery now matches all terms within the specified
|
||||
|
|
|
@ -48,7 +48,7 @@ final class DisjunctionMaxScorer extends DisjunctionScorer {
|
|||
@Override
|
||||
protected float score(DisiWrapper topList) throws IOException {
|
||||
float scoreSum = 0;
|
||||
float scoreMax = 0;
|
||||
float scoreMax = Float.NEGATIVE_INFINITY;
|
||||
for (DisiWrapper w = topList; w != null; w = w.next) {
|
||||
final float subScore = w.scorer.score();
|
||||
scoreSum += subScore;
|
||||
|
|
|
@ -509,6 +509,22 @@ public class TestDisjunctionMaxQuery extends LuceneTestCase {
|
|||
directory.close();
|
||||
}
|
||||
|
||||
public void testNegativeScore() throws Exception {
|
||||
DisjunctionMaxQuery q = new DisjunctionMaxQuery(
|
||||
Arrays.asList(
|
||||
new BoostQuery(tq("hed", "albino"), -1f),
|
||||
new BoostQuery(tq("hed", "elephant"), -1f)
|
||||
), 0.0f);
|
||||
|
||||
ScoreDoc[] h = s.search(q, 1000).scoreDocs;
|
||||
|
||||
assertEquals("all docs should match " + q.toString(), 4, h.length);
|
||||
|
||||
for (int i = 0; i < h.length; i++) {
|
||||
assertTrue("score should be negative", h[i].score < 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** macro */
|
||||
protected Query tq(String f, String t) {
|
||||
return new TermQuery(new Term(f, t));
|
||||
|
|
Loading…
Reference in New Issue