FieldExpression¶
FieldExpression is a string parser used to parse field expressions.
It can reassemble the parsing result into a Filter object of LynseDB, which can filter the query result. Its main implementation idea is to efficiently create Filters without requiring users to learn the use of complex filtering components such as MatchRange and FieldCondition.
It is an important component of LynseDB and can effectively improve the user-friendliness of LynseDB.
-
Supported syntax:
- :field: represents a field, e.g., :order:, :name:, etc.
- :id: special reserved word for matching IDs
-
Supported comparison operators:
- ==
- !=
- >=
- <=
- >
- <
-
Supported logical operators:
- and
- or
- not
- in
-
Supported parentheses:
- ()
-
Examples:
- :order: > 1
- :order: >= 1
- :order: >= 1 and :name: >= 1.3
- not (:order: == 2)
- :order: >= 1 and :name: != 1.3 and (:order: == 2 or :name: == 3) and not (:tt: == 2)
- :id: in [1, 2]
- :id: not in [1, 2]
- :id: in [1, 2] and :order: >= 1 and :name: >= 1.3 and (:order: == 2 or :name: == 3) and not (:tt: == 2)
-
Usage:
-
Efficient syntax:
- Use () to group expressions for better readability and maintainability.
Specially when using
not
operator. - Use
not in
instead ofnot :field: in [value]
when possible. - Use
not (:field: in [value])
ornot (:field: in [value])
, it can be more efficient.
- Use () to group expressions for better readability and maintainability.
Specially when using