Class SearchExpression

java.lang.Object
org.apache.juneau.commons.beanquery.SearchExpression

public final class SearchExpression extends Object
One node of the parse tree produced by SearchExpressionParser: the resolved, validated form of a column's $-search expression that a context walks to filter rows or build SQL.

A node is one of two shapes:

  • A literal (isLiteral()): a bare pattern token or a literal argument of a leaf operator (for example OPEN in $eq(OPEN)). Its text is value(); it has no args().
  • A function (isFunction()): a $-operator invocation. Its name() is the $-name, operator() is the resolved SearchOperator, and args() are the argument nodes — literal nodes for a leaf operator, or nested function nodes for a combinator.

This tree is the parser's output, not a wire format: a BeanQuery carries only raw expression strings, and engines call the parser themselves. See SearchExpressionParser.

Example:

SearchExpression node = SearchExpressionParser.parse("$contains(err)", SearchOperatorSet.standard()); if (node.isFunction()) evaluate(node.name(), node.literalArgs()); // name() == "$contains", literalArgs() == ["err"]

Example (typed values):

SearchExpression e = SearchExpressionParser.parse("$eq(42)", SearchOperatorSet.standard()); // After QueryResolver types it against a NUMERIC column, the arg's typedValue() is a BigDecimal, not "42". Object arg = e.typedArgs().get(0);

Since:
10.0.0
  • Method Details

    • isLiteral

      public boolean isLiteral()
      Whether this is a literal (a bare pattern token or a leaf argument).
      Returns:
      true if a literal.
    • isFunction

      public boolean isFunction()
      Whether this is a $-operator invocation.
      Returns:
      true if a function.
    • name

      public String name()
      The operator $-name, or null for a literal.
      Returns:
      The name, or null.
    • value

      public String value()
      The literal text, or null for a function.
      Returns:
      The value, or null.
    • isQuoted

      public boolean isQuoted()
      Whether this literal was written as a quoted value ("a*" or 'a*') in the search string.

      A quoted literal is never wildcard-interpreted: name="a*" matches the literal text a* (case-insensitive substring, like any bare value without wildcards), while name=a* treats * as a wildcard. Always false for a function node.

      Returns:
      true if this literal was quoted in the source search string.
    • operator

      The resolved operator, or null for a literal.
      Returns:
      The operator, or null.
    • args

      The argument nodes (empty for a literal or a zero-arg function such as $blank()).
      Returns:
      An unmodifiable list of argument nodes.
    • argCount

      public int argCount()
      The number of argument nodes.
      Returns:
      The argument count.
    • literalArgs

      public List<String> literalArgs()
      This function's arguments as literal strings — the shape a leaf operator (built-in or custom) consumes.

      A non-literal (nested function) argument contributes its $-name so the list length always equals argCount().

      Returns:
      An unmodifiable list of the literal argument strings.
    • typedValue

      public Object typedValue()
      The parsed, type-aware value for this node.

      For a literal node that QueryResolver typed (a bare literal, or an argument of a value operator such as $eq/$in/$gt/$between), this is the parsed object (BigDecimal, Boolean, or a java.time type). For every other node (untyped literals, function nodes) this returns value() unchanged, so callers can read typedValue() instead of value() without a null check.

      Returns:
      The typed value, or the literal text.
    • typedArgs

      public List<Object> typedArgs()
      This function's arguments' typed values, in order - the shape a value operator, or a custom operator opting into typedArgs(true), consumes instead of literalArgs().

      A nested function argument contributes its $-name, exactly as in literalArgs(), so the list never contains null for a function argument and its length always equals argCount().

      Returns:
      An unmodifiable list of the typed argument values, one per args() entry.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object