You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2016/10/15 23:55:15 UTC
[03/24] lucene-solr:jira/solr-8396: LUCENE-7486: DisjunctionMaxQuery
does not work correctly with queries that return negative scores
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/d25aba23
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d25aba23
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d25aba23
Branch: refs/heads/jira/solr-8396
Commit: d25aba2336fe8e7e2a831ccceb6635eb8881cf0f
Parents: 2bbca4c
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:07:35 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/d25aba23/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 0647df0..0686cc1 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d25aba23/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/d25aba23/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));