You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2018/06/14 10:17:37 UTC

[1/3] lucene-solr:branch_7x: LUCENE-8357: Fix function score explanations

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 <ro...@apache.org>
Authored: Thu Jun 14 09:26:37 2018 +0100
Committer: Alan Woodward <ro...@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


[2/3] lucene-solr:branch_7_4: LUCENE-8357: Fix function score explanations

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

Branch: refs/heads/branch_7_4
Commit: 325255766c518fdb049c36cb343c43de86273ee8
Parents: 5b36a35
Author: Alan Woodward <ro...@apache.org>
Authored: Thu Jun 14 09:26:37 2018 +0100
Committer: Alan Woodward <ro...@apache.org>
Committed: Thu Jun 14 10:57:47 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/32525576/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 96f962d..7182bb1 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -176,6 +176,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/32525576/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/32525576/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


[3/3] lucene-solr:master: LUCENE-8357: Fix function score explanations

Posted by ro...@apache.org.
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 <ro...@apache.org>
Authored: Thu Jun 14 09:26:37 2018 +0100
Committer: Alan Woodward <ro...@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