lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject [1/3] lucene-solr:branch_7x: LUCENE-8357: Fix function score explanations
Date Thu, 14 Jun 2018 10:17:37 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7_4 5b36a35d4 -> 325255766
  refs/heads/branch_7x 5090161eb -> fffdc506b
  refs/heads/master 228a84fd6 -> 6f24be945


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/fffdc506
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/fffdc506
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/fffdc506

Branch: refs/heads/branch_7x
Commit: fffdc506b5e5767ba89ee46b81ce5d9d1ebd3d84
Parents: 5090161
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 10:57:29 2018 +0100

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


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/fffdc506/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 64c368f..8f383f6 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -184,6 +184,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/fffdc506/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 e6c01c0..9e35c99 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
@@ -231,6 +231,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() * boostExpl.getValue(),
+          "product of:", scoreExplanation, boostExpl);
+    }
+
+    @Override
     public int hashCode() {
       return Objects.hash(boost);
     }
@@ -305,5 +318,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/fffdc506/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 47df46b..0e59a2b 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
@@ -27,6 +27,7 @@ import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.DoubleValuesSource;
+import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.QueryUtils;
@@ -126,9 +127,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
@@ -147,8 +151,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