aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/main')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java20
-rw-r--r--config-model/src/main/javacc/SDParser.jj51
2 files changed, 71 insertions, 0 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 77182e05f9b..68faa462fdd 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
@@ -673,6 +673,26 @@ public class RankProfile implements Cloneable {
inputFeatures.put(ref, declaredType);
}
+ public static class ExecuteOperation {
+ public enum Phase { onmatch, onrerank, onsummary}
+ final Phase phase;
+ final String attribute;
+ final String operation;
+ ExecuteOperation(Phase phase, String attribute, String operation) {
+ this.phase = phase;
+ this.attribute = attribute;
+ this.operation = operation;
+ }
+ }
+ private final List<ExecuteOperation> executeOperations = new ArrayList<>();
+
+ public void addExecuteOperation(ExecuteOperation.Phase phase, String attribute, String operation) {
+ executeOperations.add(new ExecuteOperation(phase, attribute, operation));
+ addRankProperty("vespa.execute." + phase + ".attribute", attribute);
+ addRankProperty("vespa.execute." + phase + ".operation", operation);
+ }
+ public List<ExecuteOperation> getExecuteOperations() { return executeOperations; }
+
public RankingExpressionFunction findFunction(String name) {
RankingExpressionFunction function = functions.get(name);
return ((function == null) && (getInherited() != null))
diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj
index 01a8ac21658..11ebd7c8b3e 100644
--- a/config-model/src/main/javacc/SDParser.jj
+++ b/config-model/src/main/javacc/SDParser.jj
@@ -205,6 +205,11 @@ TOKEN :
| < LOOSE: "loose" >
| < STRICT: "strict" >
| < DOCUMENT: "document" >
+| < EXECUTE: "execute" >
+| < OPERATION: "operation" >
+| < ON_MATCH: "on-match" >
+| < ON_RERANK: "on-rerank" >
+| < ON_SUMMARY: "on-summary" >
| < STRUCT: "struct" >
| < INHERITS: "inherits" >
| < FIELD: "field" >
@@ -2058,6 +2063,7 @@ Object rankProfileItem(RankProfile profile) : { }
| firstPhase(profile)
| matchPhase(profile)
| function(profile)
+ | execute(profile)
| ignoreRankFeatures(profile)
| numThreadsPerSearch(profile)
| minHitsPerThread(profile)
@@ -2087,6 +2093,43 @@ void inheritsRankProfile(RankProfile profile) :
}
/**
+ * This rule consumes an execute statement of a rank-profile.
+ *
+ * @param profile The profile to modify.
+ */
+void execute(RankProfile profile) :
+{
+}
+{
+ <EXECUTE> lbrace() (execute_operation(profile) <NL>)+ <RBRACE>
+ { }
+}
+
+void execute_operation(RankProfile profile) :
+{
+ String attribute, operation;
+ RankProfile.ExecuteOperation.Phase phase;
+}
+{
+ ( <ON_MATCH> { phase = RankProfile.ExecuteOperation.Phase.onmatch; }
+ | <ON_RERANK> { phase = RankProfile.ExecuteOperation.Phase.onrerank; }
+ | <ON_SUMMARY> { phase = RankProfile.ExecuteOperation.Phase.onsummary; }
+ )
+ lbrace() attribute = identifier() operation = execute_expr() (<NL>)* <RBRACE>
+ { profile.addExecuteOperation(phase, attribute, operation); }
+}
+
+String execute_expr() :
+{
+ String op;
+ Number constant = null;
+}
+{
+ (("++" | "--") { op = token.image; } | ("+=" | "-=" | "*=" | "/=" | "%=" | "=") { op = token.image; } constant = consumeNumber())
+ { return constant != null ? (op + constant) : op; }
+}
+
+/**
* This rule consumes a function statement of a rank-profile.
*
* @param profile The profile to modify.
@@ -2844,6 +2887,14 @@ double consumeFloat() : { }
<DOUBLE> { return Double.valueOf(token.image); }
}
+Number consumeNumber() :
+{
+ Number num;
+}
+{
+ (num = consumeFloat() | num = consumeLong()) { return num; }
+}
+
/**
* This rule consumes an opening brace with leading and trailing newline tokens.
*/