"contains" in drools is used for Collections, not Strings. You should use the
"matches" leyword instead.
See the docs:
http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.htm
Find section "6.5.2.1.1.3.1. Operators"
'"contains" and "not contains" is only applicable to Collection
type fields'
It could be documented a bit more clearly, especially as java.lang.String.contains() could
make one thing that's what it's for in drools as well.
--- On Fri, 1/16/09, Zeke <xanadu860122(a)gmail.com> wrote:
From: Zeke <xanadu860122(a)gmail.com>
Subject: [rules-users] meet Operator 'Operator = 'contains'' does not
exist for StringEvaluator error
To: rules-users(a)lists.jboss.org
Date: Friday, January 16, 2009, 1:16 AM
Hi, all:
I meet a strange error when use "contains"
operator on string type, My
rule is like below:
> package org.drools.examples;
>
> import org.drools.examples.HelloWorldExample.Message;
>
> rule "check str contains"
> dialect "java"
> when
> m:Message( message contains "Hello"
)
> then
> System.out.println( "===check str
contains ok===" );
> end
It throw below exception:
> Exception in thread "main"
java.lang.RuntimeException: Operator 'Operator
> = 'contains'' does not exist for
StringEvaluator
> at
>
org.drools.base.evaluators.StringFactory.getEvaluator(StringFactory.java:70)
> at
org.drools.base.ValueType.getEvaluator(ValueType.java:166)
> at
>
org.drools.rule.builder.PatternBuilder.getEvaluator(PatternBuilder.java:900)
> at
>
org.drools.rule.builder.PatternBuilder.buildRestriction(PatternBuilder.java:714)
> at
>
org.drools.rule.builder.PatternBuilder.buildRestriction(PatternBuilder.java:625)
> at
>
org.drools.rule.builder.PatternBuilder.createRestriction(PatternBuilder.java:434)
> at
>
org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:308)
> at
>
org.drools.rule.builder.PatternBuilder.buildConstraint(PatternBuilder.java:199)
> at
>
org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:168)
> at
org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:93)
> at
>
org.drools.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:69)
> at
org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:53)
> at
org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:446)
> at
>
org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:304)
> at
>
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
> at
>
org.drools.examples.HelloWorldExample.main(HelloWorldExample.java:28)
>
But if I use a "deep" str field, this issue does
not exist, Everything goes
well.
The drl is like below:
> package org.drools.examples;
>
> import org.drools.examples.HelloWorldExample.Message;
>
> rule "check deep str contains"
> dialect "java"
> when
> m:Message( sec.fir.msg contains
"Hello" )
> then
> System.out.println( "===check deep str
contains ok===" );
> end
It seems a bug, but I am not sure. I attached my test code
and the two drl
files.
I use below jars to compile and run this test case:
> antlr-runtime-3.0.jar
> core-3.2.3.v_686_R32x.jar
> drools-compiler-4.0.7.jar
> drools-core-4.0.7.jar
> drools-decisiontables-4.0.7.jar
> drools-jsr94-4.0.7.jar
> janino-2.5.10.jar
> jsr94-1.1.jar
> mvel-1.3.12-java1.4.2.jar
Can everyone kindly give me any suggestion?
Thanks!
- Zeke
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users