summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-02-17 15:56:06 +0100
committerJon Bratseth <bratseth@oath.com>2018-02-17 15:56:06 +0100
commit6af81f91a391eedc7938604fa6ac7c9681ef6d1f (patch)
tree840b5e9b26ed081ef67f65eaedd2083932789d65
parent6bc39e044bc13f7b1be78890c6e171945a439603 (diff)
Cleanup
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/Arguments.java2
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java38
2 files changed, 17 insertions, 23 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/Arguments.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/Arguments.java
index d7163fe9166..ea590ec7139 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/Arguments.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/Arguments.java
@@ -43,7 +43,7 @@ public final class Arguments implements Serializable {
this.expressions = b.build();
}
- /** Returns an unmodifiable list of the expressions in this */
+ /** Returns an unmodifiable list of the expressions in this, never null */
public List<ExpressionNode> expressions() { return expressions; }
/** Evaluate all arguments in this */
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
index f59719db2f2..81c8d203167 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
@@ -70,28 +70,22 @@ public final class ReferenceNode extends CompositeNode {
String myOutput = getOutput();
List<ExpressionNode> myArguments = getArguments().expressions();
- String resolvedArgument = context.getBinding(myName);
- if (resolvedArgument != null && reference.isIdentifier()) {
- // Replace this whole node with the value of the argument value that it maps to
- myName = resolvedArgument;
- myArguments = null;
- myOutput = null;
- } else if (context.getFunction(myName) != null) {
- // Replace by the referenced expression
- ExpressionFunction function = context.getFunction(myName);
- if (function != null && myArguments != null && function.arguments().size() == myArguments.size() && myOutput == null) {
- String myPath = getName() + getArguments().expressions();
- if (path.contains(myPath)) {
- throw new IllegalStateException("Cycle in ranking expression function: " + path);
- }
- path.addLast(myPath);
- ExpressionFunction.Instance instance = function.expand(context, myArguments, path);
- path.removeLast();
- context.addFunctionSerialization(RankingExpression.propertyName(instance.getName()), instance.getExpressionString());
- myName = "rankingExpression(" + instance.getName() + ")";
- myArguments = null;
- myOutput = null;
- }
+ if (reference.isIdentifier() && context.getBinding(myName) != null) {
+ // a bound identifier: replace by the value it is bound to
+ return context.getBinding(myName);
+ }
+
+ ExpressionFunction function = context.getFunction(myName);
+ if (function != null && function.arguments().size() == myArguments.size() && myOutput == null) {
+ // a function reference: replace by the referenced function wrapped in rankingExpression
+ String myPath = getName() + getArguments().expressions();
+ if (path.contains(myPath))
+ throw new IllegalStateException("Cycle in ranking expression function: " + path);
+ path.addLast(myPath);
+ ExpressionFunction.Instance instance = function.expand(context, myArguments, path);
+ path.removeLast();
+ context.addFunctionSerialization(RankingExpression.propertyName(instance.getName()), instance.getExpressionString());
+ return "rankingExpression(" + instance.getName() + ")";
}
// Always print the same way, the magic is already done.