简体   繁体   English

流口水:相同情况下两次开除

[英]Drools: Rule firing twice for the same case

This rule fires twice although there is only one matching case. 尽管只有一种匹配的情况,但此规则会触发两次。 I use Drools 6.5.0. 我使用Drools 6.5.0。 Final. 最后。 Looking at the log, it takes $card2 as $card1 and vice versa in the second round. 查看日志,在第二轮中将$ card2作为$ card1,反之亦然。

rule "Rule1"
salience 1
when
  $card1 : (used == false)
  $card2 : (used == false, number = $card1.number)
  exists Hand(name == name1)
  exists Hand(name == name2 || name == name3)
  not Hand(name == name4)

then
    $card1.setUsed(true); $card2.setUsed(true);
    insert(new Hand(name1, $card1, $card2));

end

First of all, your rule looks malformed to me. 首先,您的规则对我来说似乎是不正确的。 The 2 first patterns are missing their types and there are variables (ie name1 ) that don't come from anywhere. 前两个模式缺少它们的类型,并且有一些变量(即name1 )不是来自任何地方。

Second, remember that the LHS of the rules in Drools works kind of like an SQL statement. 其次,请记住,Drools中的规则的LHS类似于SQL语句。 If you don't specify any relationship between your patterns, the cartesian product of them will be used. 如果您在模式之间未指定任何关系,则将使用它们的笛卡尔积。

Hope it helps 希望能帮助到你

No-Loop attribute for rule makes sure the same rule is not re-triggered when updates/ modify of same object that is used in the when condition takes place in the then statement. 规则的No-Loop属性可确保在then语句中的when条件发生时更新或修改同一对象时,不会重新触发同一规则。

The way to define no-loop is as below: 定义无环的方法如下:

rule "Rule1"
no-loop true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM