Class SearchExpressionParser

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

public final class SearchExpressionParser extends Object
The single public parser for the $-search language (design §5.1). Engines call it; a BeanQuery itself carries only the raw strings.
Grammar

A column's expression is one of:

  • A pattern — a bare token (case-insensitive substring / prefix / exact per the column type), optionally with * wildcards, or a value such as $100 whose leading $ is not a known operator invocation. Patterns are literal nodes. This also covers a relative-duration token such as -24h or +7d ([+-]<n>(ms|s|m|h|d)) or a signed ISO-8601 duration such as -PT24H: the parser applies no special grammar to it, since it is already an ordinary pattern; a TIMESTAMP or duration column's typed conversion (not this parser) is what resolves it relative to request time.
  • An operator — $name(arg,...) where $name is in the supplied SearchOperatorSet. Leaf-operator arguments are literals; combinator ($and/$or/ $not) arguments are themselves expressions. Columns combine with and; $or/$and/ $not combine within one column.
Literal dollar

$$ is a literal $ everywhere. A token that starts with $$ is always a pattern (never an operator), and every $$ inside a literal decodes to a single $. So $$eq(x) is the literal text $eq(x), while $eq(x) is the operator.

Quoting

A quoted literal argument (design §5.1) may contain its own delimiter by doubling it — "" inside a double-quoted value, or '' inside a single-quoted value, decodes to one literal quote character of that same kind. So $eq("a""b") is the literal text a"b. This doubling decode is independent of, and composes with, the $$ → $ decoding above.

Errors

An unknown $name(...), a malformed expression (unclosed/unbalanced parentheses, junk after the close paren, a stray comma, a wrong argument count), or an empty expression throws BeanQuerySyntaxException. There is no "incomplete draft" state on the server: a request-facing adapter catches the exception and surfaces the message.

Example:

try { SearchExpression node = SearchExpressionParser.parse("$gt(10)", SearchOperatorSet.standard()); // node.isFunction() == true, node.name() == "$gt", node.literalArgs() == ["10"] } catch (BeanQuerySyntaxException e) { // e.code() names the specific grammar problem, e.g. Code.UNKNOWN_OPERATOR or Code.UNBALANCED }

Since:
10.0.0
  • Method Details

    • parse

      public static SearchExpression parse(String raw, SearchOperatorSet operators)
      Parses a raw column-search expression.
      Parameters:
      raw - The raw expression string (a pattern or $name(...)). Must not be null or blank.
      operators - The operator set that defines which $-names are recognized. Must not be null.
      Returns:
      The parsed expression, never null.
      Throws:
      BeanQuerySyntaxException - If the expression is empty, names an unknown operator, or is malformed.