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 2019/02/05 09:49:44 UTC
[lucene-solr] branch master updated: LUCENE-8655: Add .getSource()
method to FunctionScoreQuery
This is an automated email from the ASF dual-hosted git repository.
romseygeek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/master by this push:
new 1b077cf LUCENE-8655: Add .getSource() method to FunctionScoreQuery
1b077cf is described below
commit 1b077cf0e3108d70c46c0a0f9f7acd75c2d7a280
Author: Alan Woodward <ro...@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 9c2d634..04042ca 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -205,6 +205,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);
+
+
+ }
+
}