You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2016/10/11 16:08:55 UTC
lucene-solr:branch_6x: LUCENE-7486: DisjunctionMaxQuery does not work
correctly with queries that return negative scores
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x ca625ea56 -> 3bd3a4cbc
LUCENE-7486: DisjunctionMaxQuery does not work correctly with queries that return negative scores
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/3bd3a4cb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/3bd3a4cb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/3bd3a4cb
Branch: refs/heads/branch_6x
Commit: 3bd3a4cbc460db20e29e242f27041c20a03218de
Parents: ca625ea
Author: Uwe Schindler <us...@apache.org>
Authored: Tue Oct 11 18:07:35 2016 +0200
Committer: Uwe Schindler <us...@apache.org>
Committed: Tue Oct 11 18:08:43 2016 +0200
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +++
.../apache/lucene/search/DisjunctionMaxScorer.java | 2 +-
.../lucene/search/TestDisjunctionMaxQuery.java | 16 ++++++++++++++++
3 files changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3bd3a4cb/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index a5693f0..9a29b7b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -32,6 +32,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
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3bd3a4cb/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
index 3d6fbda..2356f5e 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3bd3a4cb/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
index 79c32d3..87046c7 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
@@ -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));