lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject [3/3] lucene-solr:master: LUCENE-8357: Fix function score explanations
Date Thu, 14 Jun 2018 10:17:39 GMT
LUCENE-8357: Fix function score explanations


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/6f24be94
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6f24be94
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6f24be94

Branch: refs/heads/master
Commit: 6f24be9457e4f4f0de9af1d78f96754110348f67
Parents: 228a84f
Author: Alan Woodward <romseygeek@apache.org>
Authored: Thu Jun 14 09:26:37 2018 +0100
Committer: Alan Woodward <romseygeek@apache.org>
Committed: Thu Jun 14 11:07:30 2018 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 +++
 .../queries/function/FunctionScoreQuery.java    | 22 ++++++++++++++++++++
 .../function/TestFunctionScoreQuery.java        | 10 +++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6f24be94/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index ca8fa58..8b18dd5 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -291,6 +291,9 @@ Bug Fixes
   position increment when the preservePositionIncrement setting is false.
   (David Smiley, Jim Ferenczi)
 
+* LUCENE-8357: FunctionScoreQuery.boostByQuery() and boostByValue() were
+  producing truncated Explanations (Markus Jelsma, Alan Woodward)
+
 Other
 
 * LUCENE-8301: Update randomizedtesting to 2.6.0. (Dawid Weiss)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6f24be94/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
index de0e6d4..38b9732 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
@@ -271,6 +271,19 @@ public final class FunctionScoreQuery extends Query {
     }
 
     @Override
+    public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation)
throws IOException {
+      if (scoreExplanation.isMatch() == false) {
+        return scoreExplanation;
+      }
+      Explanation boostExpl = boost.explain(ctx, docId, scoreExplanation);
+      if (boostExpl.isMatch() == false) {
+        return scoreExplanation;
+      }
+      return Explanation.match(scoreExplanation.getValue().doubleValue() * boostExpl.getValue().doubleValue(),
+          "product of:", scoreExplanation, boostExpl);
+    }
+
+    @Override
     public int hashCode() {
       return Objects.hash(boost);
     }
@@ -345,5 +358,14 @@ public final class FunctionScoreQuery extends Query {
     public boolean isCacheable(LeafReaderContext ctx) {
       return query.isCacheable(ctx);
     }
+
+    @Override
+    public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation)
throws IOException {
+      Explanation inner = query.explain(ctx, docId, scoreExplanation);
+      if (inner.isMatch() == false) {
+        return inner;
+      }
+      return Explanation.match(boost, "Matched boosting query " + query.toString());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6f24be94/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
index b865cb7..d97d5ad 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
@@ -134,9 +134,12 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
     assertEquals(plain.totalHits, docs.totalHits);
     for (int i = 0; i < expectedDocs.length; i++) {
       assertEquals(expectedDocs[i], docs.scoreDocs[i].doc);
-
     }
 
+    Explanation expl = searcher.explain(fq, 4);
+    assertTrue(expl.toString().contains("first"));
+    assertTrue(expl.toString().contains("iii"));
+
   }
 
   // BoostingQuery equivalent
@@ -155,8 +158,11 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
     assertEquals(plain.totalHits, docs.totalHits);
     for (int i = 0; i < expectedDocs.length; i++) {
       assertEquals(expectedDocs[i], docs.scoreDocs[i].doc);
-
     }
+
+    Explanation expl = searcher.explain(fq, 6);
+    assertTrue(expl.toString().contains("rechecking"));
+    assertTrue(expl.toString().contains("text"));
   }
 
   // check boosts with non-distributive score source


Mime
View raw message