lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject [lucene-solr] branch branch_8x updated: LUCENE-8655: Add .getSource() method to FunctionScoreQuery
Date Tue, 05 Feb 2019 09:49:43 GMT
This is an automated email from the ASF dual-hosted git repository.

romseygeek pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 66fb333  LUCENE-8655: Add .getSource() method to FunctionScoreQuery
66fb333 is described below

commit 66fb333bdd390d2bd5c5119706ca6e99925ffff3
Author: Alan Woodward <romseygeek@apache.org>
AuthorDate: Tue Feb 5 09:33:44 2019 +0000

    LUCENE-8655: Add .getSource() method to FunctionScoreQuery
---
 lucene/CHANGES.txt                                 |  3 +++
 .../queries/function/FunctionScoreQuery.java       |  7 +++++++
 .../queries/function/TestFunctionScoreQuery.java   | 24 ++++++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index bb0573e..453779e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -190,6 +190,9 @@ New Features
 * LUCENE-8646: New interval functions: Intervals.prefix() and Intervals.wildcard()
   (Alan Woodward)
 
+* LUCENE-8655: Add a getter in FunctionScoreQuery class in order to access to the 
+  underlying DoubleValuesSource. (GĂ©rald Quaire via Alan Woodward)
+
 Improvements
 
 * LUCENE-7997: Add BaseSimilarityTestCase to sanity check similarities.
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 38b9732..5268a43 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
@@ -65,6 +65,13 @@ public final class FunctionScoreQuery extends Query {
   }
 
   /**
+   * @return the underlying value source
+   */
+  public DoubleValuesSource getSource() {
+    return source;
+  }
+
+  /**
    * Returns a FunctionScoreQuery where the scores of a wrapped query are multiplied by
    * the value of a DoubleValuesSource.
    *
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 3d3f54e..952e6a4 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
@@ -220,4 +220,28 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
     reader.close();
     dir.close();
   }
+
+  // check access to the score source of a functionScoreQuery
+  public void testAccessToValueSource() throws Exception {
+
+    FunctionScoreQuery q1 = new FunctionScoreQuery(new TermQuery(new Term(TEXT_FIELD, "a")),
DoubleValuesSource.constant(31));
+    Query q2 = new FunctionScoreQuery(q1.getWrappedQuery(), q1.getSource());
+    QueryUtils.check(q2);
+    QueryUtils.checkEqual(q2, q1);
+
+    FunctionScoreQuery q3 = new FunctionScoreQuery(new TermQuery(new Term(TEXT_FIELD, "first")),
+            DoubleValuesSource.fromIntField(INT_FIELD));
+    Query q4 = new FunctionScoreQuery(q3.getWrappedQuery(), q3.getSource());
+    QueryUtils.checkEqual(q3, q4);
+
+    SimpleBindings bindings = new SimpleBindings();
+    bindings.add("score", DoubleValuesSource.SCORES);
+    Expression expr = JavascriptCompiler.compile("ln(score + 4)");
+    FunctionScoreQuery q5 = new FunctionScoreQuery(new TermQuery(new Term(TEXT_FIELD, "text")),
expr.getDoubleValuesSource(bindings));
+    Query q6 = new FunctionScoreQuery(q5.getWrappedQuery(), q5.getSource());
+    QueryUtils.checkEqual(q5, q6);
+
+
+  }
+
 }


Mime
View raw message