Write Rule Conditions (LHS)
masterThe Left Hand Side (LHS) defines the patterns that must match for a rule to fire.
Pattern Matching Types
- No constraints:
Person()(matches any Person fact). - Field constraints:
Person( name == "bob" ). - Field binding:
Person( $name : name == "bob" )(binds the value ofnameto variable$name). - Fact binding:
$bob : Person( name == "bob" )(binds the entire object to$bob). - Variable constraints:
Person( name == $name ).
Comparison Operators
Drools supports: >, >=, <, <=, ==, !=, contains, not contains, memberOf, not memberOf, matches, not matches.
contains: Checks if a collection or string contains a value.memberOf: Checks if a field is a member of a specific variable (collection).matches: Performs regex matching (does not require escaping/like Java).exists: Activates the rule if at least one matching fact exists (activates at most once).not: Activates if no matching facts exist.