summaryrefslogtreecommitdiffstats
path: root/searchlib/src/main
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-09-21 08:44:29 +0200
committerGitHub <noreply@github.com>2022-09-21 08:44:29 +0200
commit9f4fcf60d0cac9dfcc2da8f74640483ec5b7629f (patch)
tree09b0c9d0f898eac040c8d10be36d09a22d7a8f95 /searchlib/src/main
parent1be14007d58614d3ca44bde00100c0215f11218d (diff)
Revert "Revert "Revert "Short circuit boolean expressions"""
Diffstat (limited to 'searchlib/src/main')
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java27
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java6
2 files changed, 12 insertions, 21 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java
index ce5853155d4..580f42e67cb 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ArithmeticNode.java
@@ -47,9 +47,7 @@ public final class ArithmeticNode extends CompositeNode {
string.append("(");
Iterator<ExpressionNode> child = children.iterator();
- child.next().toString(string, context, path, this);
- if (child.hasNext())
- string.append(" ");
+ child.next().toString(string, context, path, this).append(" ");
for (Iterator<ArithmeticOperator> op = operators.iterator(); op.hasNext() && child.hasNext();) {
string.append(op.next().toString()).append(" ");
child.next().toString(string, context, path, this);
@@ -67,15 +65,16 @@ public final class ArithmeticNode extends CompositeNode {
* (even though by virtue of being a node it will be calculated before the parent).
*/
private boolean nonDefaultPrecedence(CompositeNode parent) {
- if ( parent == null) return false;
- if ( ! (parent instanceof ArithmeticNode arithmeticParent)) return false;
+ if ( parent==null) return false;
+ if ( ! (parent instanceof ArithmeticNode)) return false;
+ ArithmeticNode arithParent = (ArithmeticNode) parent;
// The line below can only be correct in both only have one operator.
// Getting this correct is impossible without more work.
- // So for now we only handle the simple case correctly, and use a safe approach by adding
+ // So for now now we only handle the simple case correctly, and use a safe approach by adding
// extra parenthesis just in case....
- return arithmeticParent.operators.get(0).hasPrecedenceOver(this.operators.get(0))
- || ((arithmeticParent.operators.size() > 1) || (operators.size() > 1));
+ return arithParent.operators.get(0).hasPrecedenceOver(this.operators.get(0))
+ || ((arithParent.operators.size() > 1) || (operators.size() > 1));
}
@Override
@@ -99,7 +98,7 @@ public final class ArithmeticNode extends CompositeNode {
for (Iterator<ArithmeticOperator> it = operators.iterator(); it.hasNext() && child.hasNext();) {
ArithmeticOperator op = it.next();
if ( ! stack.isEmpty()) {
- while (stack.size() > 1 && ! op.hasPrecedenceOver(stack.peek().op)) {
+ while (stack.peek().op.hasPrecedenceOver(op)) {
popStack(stack);
}
}
@@ -128,7 +127,9 @@ public final class ArithmeticNode extends CompositeNode {
public int hashCode() { return Objects.hash(children, operators); }
public static ArithmeticNode resolve(ExpressionNode left, ArithmeticOperator op, ExpressionNode right) {
- if ( ! (left instanceof ArithmeticNode leftArithmetic)) return new ArithmeticNode(left, op, right);
+ if ( ! (left instanceof ArithmeticNode)) return new ArithmeticNode(left, op, right);
+
+ ArithmeticNode leftArithmetic = (ArithmeticNode)left;
List<ExpressionNode> newChildren = new ArrayList<>(leftArithmetic.children());
newChildren.add(right);
@@ -148,12 +149,6 @@ public final class ArithmeticNode extends CompositeNode {
this.op = op;
this.value = value;
}
-
- @Override
- public String toString() {
- return value.toString();
- }
-
}
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java
index e23c6ec5dd5..4aee3268111 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java
@@ -20,11 +20,7 @@ public abstract class ExpressionTransformer<CONTEXT extends TransformContext> {
return new RankingExpression(expression.getName(), transform(expression.getRoot(), context));
}
- /**
- * Transforms an expression node and returns the transformed node.
- * This ic called with the root node of an expression to transform by clients of transformers.
- * Transforming nested expression nodes are left to each transformer.
- */
+ /** Transforms an expression node and returns the transformed node */
public abstract ExpressionNode transform(ExpressionNode node, CONTEXT context);
/**