From 0d406b022f3ef58ea96afe879b49bacec41b92db Mon Sep 17 00:00:00 2001
From: Johan Solbakken
+Ranking expressions support conditional logic to choose between different sub-expressions based on document attributes, query parameters, or other features.
+This enables ranking to adapt to different document types, user segments, or business rules within a single rank profile.
+
Accessing feature/function
-
The "if" function and string equality tests
+Conditional expressions
+
+The if function
+
if can be used for other purposes than encoding MLR trained decision trees.
@@ -268,6 +277,26 @@ The "if" function and string
+When comparing many values against the same discriminant value,
+the switch function provides a more readable alternative to deeply nested if statements.
+For example, the nested if expression above can be written more clearly as:
+
+switch (attribute(category)) {
+ case "restaurant": …restaurant function,
+ case "hotel": …hotel function,
+ default: …default function
+}
+
+
+Use switch when testing a single expression for equality against multiple values.
+Continue using if for different comparison operators or when each condition tests different expressions,
+such as in the tiering example above.
+
diff --git a/en/reference/ranking/ranking-expressions.html b/en/reference/ranking/ranking-expressions.html index 5529a68069..05840c42d7 100644 --- a/en/reference/ranking/ranking-expressions.html +++ b/en/reference/ranking/ranking-expressions.html @@ -172,6 +172,30 @@
+The switch function chooses between multiple sub-expressions based on matching a value.
+It provides a more readable alternative to chained if statements when selecting from several options.
+
+switch (discriminant) {
+ case value1: result1,
+ case value2: result2,
+ ...
+ default: defaultResult
+}
+
+
+The discriminant expression is compared for equality against each case value expression in order.
+When a match is found, the corresponding result expression is evaluated and returned.
+If no case matches, the default result is returned.
+All expressions may be any ranking expression.
+At least one case must be specified.
+The default must be specified.
+
The foreach function is not really part of the expression language but implemented as a
From af9efc9b0faf2225e52024a4d004d4ae42fec2bb Mon Sep 17 00:00:00 2001
From: Johan Solbakken
The The if function
The switch function
+{% include note.html content='Available from Vespa 8.626.55' %}
switch function chooses between multiple sub-expressions based on matching a value.
It provides a more readable alternative to chained if statements when selecting from several options.
From c3fd5e75fc58b899762b90030ac13ef584757fe2 Mon Sep 17 00:00:00 2001
From: Johan Solbakken The switch function
Use switch when testing a single expression for equality against multiple values.
Continue using if for different comparison operators or when each condition tests different expressions,
such as in the tiering example above.
+See the switch function reference for details.