bhabegger commented on code in PR #3139:
URL: https://github.com/apache/jackrabbit-oak/pull/3139#discussion_r4073125666


##########
oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/util/FunctionIndexProcessor.java:
##########
@@ -105,11 +122,59 @@ public static String[] getFunctionCode(String 
functionDescription) {
         if (functionDescription == null) {
             return null;
         }
-        return functionDescription.split("\\*");
+        ArrayList<String> tokens = new ArrayList<>();
+        StringBuilder current = new StringBuilder();
+        boolean inLiteral = false;
+        for (int i = 0; i < functionDescription.length(); i++) {
+            char c = functionDescription.charAt(i);
+            if (inLiteral) {
+                current.append(c);
+                if (c == '\'') {
+                    if (i + 1 < functionDescription.length() && 
functionDescription.charAt(i + 1) == '\'') {
+                        // an escaped quote within the literal
+                        current.append('\'');
+                        i++;
+                    } else {
+                        inLiteral = false;
+                    }
+                }
+            } else if (c == '\'') {
+                inLiteral = true;
+                current.append(c);
+            } else if (c == '*') {
+                tokens.add(current.toString());
+                current.setLength(0);
+            } else {
+                current.append(c);
+            }
+        }
+        tokens.add(current.toString());
+        return tokens.toArray(new String[0]);
     }
 
     private static PropertyState calculateFunction(String functionName,
                                                    Deque<PropertyState> stack) 
{
+        if ("if".equals(functionName)) {
+            // if(condition, trueValue, falseValue)
+            PropertyState condition = stack.pop();
+            PropertyState trueValue = stack.pop();
+            PropertyState falseValue = stack.pop();
+            return isTruthy(condition) ? trueValue : falseValue;
+        }
+        if ("exists".equals(functionName)) {
+            PropertyState operand = stack.pop();
+            return PropertyStates.createProperty("value",
+                    operand != EMPTY_PROPERTY_STATE, Type.BOOLEAN);
+        }
+        if ("op".equals(functionName)) {
+            // op(a, operator, b); operator is typically a quoted string
+            // literal, but can be any operand that evaluates to one of the
+            // known operator strings (e.g. a property reference)
+            PropertyState a = stack.pop();
+            PropertyState operator = stack.pop();
+            PropertyState b = stack.pop();
+            return calculateOp(a, operator, b);
+        }
         PropertyState ps = stack.pop();

Review Comment:
   pop here before "coalesce" and not before "if" seems surprising...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to