diff options
13 files changed, 60 insertions, 35 deletions
diff --git a/config-model/src/test/derived/rankexpression/macro.expression b/config-model/src/test/derived/rankingexpression/macro.expression index 054b025b2e7..054b025b2e7 100644 --- a/config-model/src/test/derived/rankexpression/macro.expression +++ b/config-model/src/test/derived/rankingexpression/macro.expression diff --git a/config-model/src/test/derived/rankexpression/overflow.expression b/config-model/src/test/derived/rankingexpression/overflow.expression index 4d3a6faeeb5..4d3a6faeeb5 100644 --- a/config-model/src/test/derived/rankexpression/overflow.expression +++ b/config-model/src/test/derived/rankingexpression/overflow.expression diff --git a/config-model/src/test/derived/rankexpression/rank-profiles.cfg b/config-model/src/test/derived/rankingexpression/rank-profiles.cfg index 6400870b0c4..6bad0434ac3 100644 --- a/config-model/src/test/derived/rankexpression/rank-profiles.cfg +++ b/config-model/src/test/derived/rankingexpression/rank-profiles.cfg @@ -363,3 +363,12 @@ rankprofile[].fef.property[].name "vespa.match.feature" rankprofile[].fef.property[].value "rankingExpression(mymul)" rankprofile[].fef.property[].name "vespa.type.attribute.t1" rankprofile[].fef.property[].value "tensor(m{},v[3])" +rankprofile[].name "withboolean" +rankprofile[].fef.property[].name "rankingExpression(mytrue).rankingScript" +rankprofile[].fef.property[].value "1.0" +rankprofile[].fef.property[].name "rankingExpression(myfalse).rankingScript" +rankprofile[].fef.property[].value "0.0" +rankprofile[].fef.property[].name "rankingExpression(mybooleanexpression).rankingScript" +rankprofile[].fef.property[].value "5.0" +rankprofile[].fef.property[].name "vespa.type.attribute.t1" +rankprofile[].fef.property[].value "tensor(m{},v[3])" diff --git a/config-model/src/test/derived/rankexpression/rankexpression.expression b/config-model/src/test/derived/rankingexpression/rankexpression.expression index d6cb73c829d..d6cb73c829d 100644 --- a/config-model/src/test/derived/rankexpression/rankexpression.expression +++ b/config-model/src/test/derived/rankingexpression/rankexpression.expression diff --git a/config-model/src/test/derived/rankexpression/rankexpression.sd b/config-model/src/test/derived/rankingexpression/rankexpression.sd index 73eb1cadadb..25d657eaf0b 100644 --- a/config-model/src/test/derived/rankexpression/rankexpression.sd +++ b/config-model/src/test/derived/rankingexpression/rankexpression.sd @@ -69,7 +69,8 @@ search rankexpression { rank-features: attribute(foo1).out attribute(bar1) rank-features { attribute(foo2).out attribute(bar2).out } rank-features { - attribute(foo3).out attribute(bar3).out } + attribute(foo3).out attribute(bar3).out + } rank-features { attribute(foo4).out attribute(bar4).out @@ -101,7 +102,8 @@ search rankexpression { summary-features: attribute(foo1).out attribute(bar1) summary-features { attribute(foo2).out attribute(bar2).out } summary-features { - attribute(foo3).out attribute(bar3).out } + attribute(foo3).out attribute(bar3).out + } summary-features { attribute(foo4).out attribute(bar4).out @@ -162,10 +164,10 @@ search rankexpression { second-phase { expression: fourtimessum(match,rankBoost) } - macro fourtimessum(var1, var2) { + function fourtimessum(var1, var2) { expression: 4*(var1+var2) } - macro myfeature() { + function myfeature() { expression { 70 * fieldMatch(title).completeness * pow(0 - fieldMatch(title).earliness, 2) + 30 * pow(0 - fieldMatch(description).earliness, 2) @@ -187,21 +189,21 @@ search rankexpression { second-phase { expression: fourtimessum(match,match) + mysummaryfeature + myfeature } - macro fourtimessum(var1, var2) { + function fourtimessum(var1, var2) { expression: 4*(var1+var2) } - macro myfeature() { + function myfeature() { expression { 70 * fieldMatch(title).completeness * pow(0 - fieldMatch(title).earliness, 2) + 30 * pow(0 - fieldMatch(description).earliness, 2) } } - macro mysummaryfeature() { + function mysummaryfeature() { expression { 70 * fieldMatch(title).completeness } } - macro mysummaryfeature2() { + function mysummaryfeature2() { expression { 71 * fieldMatch(title).completeness } @@ -213,7 +215,7 @@ search rankexpression { } rank-profile macros3 { - macro onlyusedinsummaryfeature() { + function onlyusedinsummaryfeature() { expression: 5 } summary-features { @@ -229,7 +231,7 @@ search rankexpression { } rank-profile macros-inherited inherits macros2 { - macro mysummaryfeature() { + function mysummaryfeature() { expression { 80 * fieldMatch(title).completeness } @@ -250,7 +252,7 @@ search rankexpression { } rank-profile macros-inherited3 inherits macros-inherited2 { - macro myfeature() { + function myfeature() { expression { 700 * fieldMatch(title).completeness } @@ -263,17 +265,17 @@ search rankexpression { } rank-profile macros-refering-macros { - macro m2() { + function m2() { expression: m1 * 67 } - macro m1() { + function m1() { expression { 700 * fieldMatch(title).completeness } } - macro m4() { + function m4() { expression: file:macro.expression } @@ -286,7 +288,7 @@ search rankexpression { } rank-profile macros-refering-macros-inherited inherits macros-refering-macros { - macro m3() { + function m3() { expression { if(isNan(attribute(nrtgmp))==1, 0.0, @@ -310,7 +312,7 @@ search rankexpression { } rank-profile macros-refering-macros-inherited-two-levels inherits macros-refering-macros-inherited { - macro m5() { + function m5() { expression { if(isNan(attribute(glmpfw))==1, m1, @@ -336,7 +338,8 @@ search rankexpression { match-features: attribute(foo1).out attribute(bar1) match-features { attribute(foo2).out attribute(bar2).out } match-features { - attribute(foo3).out attribute(bar3).out } + attribute(foo3).out attribute(bar3).out + } match-features { attribute(foo4) myplus @@ -346,4 +349,16 @@ search rankexpression { } } + rank-profile withboolean { + function mytrue() { + expression: true + } + function myfalse() { + expression: false + } + function mybooleanexpression() { + expression: true + if(false, 3.0, 4.0) + } + } + } diff --git a/config-model/src/test/derived/rankexpression/summary.cfg b/config-model/src/test/derived/rankingexpression/summary.cfg index aec076aa8fe..aec076aa8fe 100644 --- a/config-model/src/test/derived/rankexpression/summary.cfg +++ b/config-model/src/test/derived/rankingexpression/summary.cfg diff --git a/config-model/src/test/derived/rankexpression/summarymap.cfg b/config-model/src/test/derived/rankingexpression/summarymap.cfg index bd92b36548c..bd92b36548c 100644 --- a/config-model/src/test/derived/rankexpression/summarymap.cfg +++ b/config-model/src/test/derived/rankingexpression/summarymap.cfg diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java index 719d353f03a..ac97863b7a7 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java @@ -108,8 +108,8 @@ public class ExportingTestCase extends AbstractExportingTestCase { } @Test - public void testRankExpression() throws IOException, ParseException { - assertCorrectDeriving("rankexpression"); + public void testRankingExpression() throws IOException, ParseException { + assertCorrectDeriving("rankingexpression"); } @Test diff --git a/searchlib/abi-spec.json b/searchlib/abi-spec.json index ced2517ff9f..5a534562d32 100644 --- a/searchlib/abi-spec.json +++ b/searchlib/abi-spec.json @@ -943,7 +943,6 @@ "public final java.lang.String tag()", "public final java.util.List tagCommaLeadingList()", "public final com.yahoo.searchlib.rankingexpression.rule.ExpressionNode constantPrimitive(boolean)", - "public final com.yahoo.searchlib.rankingexpression.evaluation.Value primitiveValue()", "public final com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode tensorValueBody(com.yahoo.tensor.TensorType, java.util.List)", "public final com.yahoo.tensor.functions.DynamicTensor mappedTensorValueBody(com.yahoo.tensor.TensorType)", "public final com.yahoo.tensor.functions.DynamicTensor mixedTensorValueBody(com.yahoo.tensor.TensorType, java.util.List)", @@ -1086,6 +1085,8 @@ "public static final int MIN", "public static final int PROD", "public static final int SUM", + "public static final int TRUE", + "public static final int FALSE", "public static final int IDENTIFIER", "public static final int SINGLE_LINE_COMMENT", "public static final int DEFAULT", diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/BooleanValue.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/BooleanValue.java index 07710797ee2..eeeb26bc78f 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/BooleanValue.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/BooleanValue.java @@ -16,7 +16,7 @@ public class BooleanValue extends DoubleCompatibleValue { * Create a boolean value which is frozen at the outset. */ public static BooleanValue frozen(boolean value) { - BooleanValue booleanValue=new BooleanValue(value); + BooleanValue booleanValue = new BooleanValue(value); booleanValue.freeze(); return booleanValue; } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java index 46e833197f9..2cfe20d8131 100755 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java @@ -2,6 +2,7 @@ package com.yahoo.searchlib.rankingexpression.rule; import com.yahoo.searchlib.rankingexpression.Reference; +import com.yahoo.searchlib.rankingexpression.evaluation.BooleanValue; import com.yahoo.searchlib.rankingexpression.evaluation.Context; import com.yahoo.searchlib.rankingexpression.evaluation.Value; import com.yahoo.tensor.TensorType; @@ -39,6 +40,8 @@ public final class ConstantNode extends ExpressionNode { @Override public StringBuilder toString(StringBuilder string, SerializationContext context, Deque<String> path, CompositeNode parent) { + if (value instanceof BooleanValue) // Convert booleans to floats + return string.append(value.asBoolean() ? "1.0" : "0.0"); return string.append(value.toString()); } diff --git a/searchlib/src/main/javacc/RankingExpressionParser.jj b/searchlib/src/main/javacc/RankingExpressionParser.jj index 865820320d8..ebe1e048247 100755 --- a/searchlib/src/main/javacc/RankingExpressionParser.jj +++ b/searchlib/src/main/javacc/RankingExpressionParser.jj @@ -153,6 +153,8 @@ TOKEN : <MIN: "min"> | <PROD: "prod"> | <SUM: "sum"> | + <TRUE: "true"> | + <FALSE: "false"> | <IDENTIFIER: (["A"-"Z","a"-"z","0"-"9","_","@"](["A"-"Z","a"-"z","0"-"9","_","@","$"])*)> } @@ -797,7 +799,9 @@ String identifier() : func = binaryFunctionName() { return func.toString(); } | <IF> { return token.image; } | <IN> { return token.image; } | - <IDENTIFIER> { return token.image; } + <IDENTIFIER> { return token.image; } | + <TRUE> { return token.image; } | + <FALSE> { return token.image; } } List<String> identifierList() : @@ -854,25 +858,14 @@ ExpressionNode constantPrimitive(boolean negate) : ( <INTEGER> { value = token.image; } | <FLOAT> { value = token.image; } ) { node = new ConstantNode(Value.parse(negate ? ("-" + value) : value)); } | - <STRING> { - value = token.image; - node = new ConstantNode(Value.parse(value)); + ( <STRING> | <TRUE> | <FALSE> ) { + node = new ConstantNode(Value.parse(token.image)); if (negate) node = new NegativeNode(node); } ) { return node; } } -Value primitiveValue() : -{ - String sign = ""; -} -{ - ( <SUB> { sign = "-";} ) ? - ( <INTEGER> | <FLOAT> | <STRING> ) - { return Value.parse(sign + token.image); } -} - TensorFunctionNode tensorValueBody(TensorType type, List dimensionOrder) : { DynamicTensor dynamicTensor; diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java index efa98fba2eb..19e32c23234 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/EvaluationTestCase.java @@ -133,6 +133,10 @@ public class EvaluationTestCase { public void testBooleanEvaluation() { EvaluationTester tester = new EvaluationTester(); + // literals + tester.assertEvaluates(false, "false"); + tester.assertEvaluates(true, "true"); + // and tester.assertEvaluates(false, "0 && 0"); tester.assertEvaluates(false, "0 && 1"); |