diff options
Diffstat (limited to 'config-model/src/main/java/com')
3 files changed, 11 insertions, 17 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index 7d8860204f2..937151c0d3a 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -534,7 +534,7 @@ public class RankProfile implements Serializable, Cloneable { /** Adds a function and returns it */ public RankingExpressionFunction addFunction(ExpressionFunction function, boolean inline) { - RankingExpressionFunction rankingExpressionFunction = new RankingExpressionFunction(function, inline, Optional.empty()); + RankingExpressionFunction rankingExpressionFunction = new RankingExpressionFunction(function, inline); functions.put(function.getName(), rankingExpressionFunction); return rankingExpressionFunction; } @@ -694,7 +694,7 @@ public class RankProfile implements Serializable, Cloneable { for (Map.Entry<String, RankingExpressionFunction> entry : functions.entrySet()) { RankingExpressionFunction rankingExpressionFunction = entry.getValue(); RankingExpression compiled = compile(rankingExpressionFunction.function().getBody(), queryProfiles, importedModels, getConstants(), inlineFunctions, expressionTransforms); - compiledFunctions.put(entry.getKey(), rankingExpressionFunction.withBody(compiled)); + compiledFunctions.put(entry.getKey(), rankingExpressionFunction.withExpression(compiled)); } return compiledFunctions; } @@ -897,21 +897,18 @@ public class RankProfile implements Serializable, Cloneable { /** A function in a rank profile */ public static class RankingExpressionFunction { - private final ExpressionFunction function; + private ExpressionFunction function; /** True if this should be inlined into calling expressions. Useful for very cheap functions. */ private final boolean inline; - private Optional<TensorType> type; - - public RankingExpressionFunction(ExpressionFunction function, boolean inline, Optional<TensorType> type) { + public RankingExpressionFunction(ExpressionFunction function, boolean inline) { this.function = function; this.inline = inline; - this.type = type; } - public void setType(TensorType type) { - this.type = Optional.of(type); + public void setReturnType(TensorType type) { + this.function = function.withReturnType(type); } public ExpressionFunction function() { return function; } @@ -920,11 +917,8 @@ public class RankProfile implements Serializable, Cloneable { return inline && function.arguments().isEmpty(); // only inline no-arg functions; } - /** Returns the type this produces, or empty if not resolved */ - public Optional<TensorType> type() { return type; } - - public RankingExpressionFunction withBody(RankingExpression expression) { - return new RankingExpressionFunction(function.withBody(expression), inline, type); + public RankingExpressionFunction withExpression(RankingExpression expression) { + return new RankingExpressionFunction(function.withBody(expression), inline); } @Override diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java index c3a2673ef2b..f575d1178c0 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java @@ -208,8 +208,8 @@ public class RawRankProfile implements RankProfilesConfig.Producer { String expressionString = e.getValue().function().getBody().getRoot().toString(new StringBuilder(), context, null, null).toString(); context.addFunctionSerialization(RankingExpression.propertyName(e.getKey()), expressionString); - if (e.getValue().type().isPresent()) - context.addFunctionTypeSerialization(RankingExpression.propertyTypeName(e.getKey()), e.getValue().type().get().toString()); + if (e.getValue().function().returnType().isPresent()) + context.addFunctionTypeSerialization(RankingExpression.propertyTypeName(e.getKey()), e.getValue().function().returnType().get().toString()); else if (e.getValue().function().arguments().isEmpty()) throw new IllegalStateException("Type of function '" + e.getKey() + "' is not resolved"); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolver.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolver.java index f502af922e9..4c8b5910b78 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolver.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolver.java @@ -64,7 +64,7 @@ public class RankingExpressionTypeResolver extends Processor { TensorType type = resolveType(function.getValue().function().getBody(), "function '" + function.getKey() + "'", context); - function.getValue().setType(type); + function.getValue().setReturnType(type); } if (validate) { |