【问题标题】:How to keep track of multiple matches in drools如何在流口水中跟踪多个匹配项
【发布时间】:2019-08-31 15:05:15
【问题描述】:

我有一条规则会针对与我的产品代码匹配的产品多次触发。如何获得所有已匹配的产品?我知道我可以使用全局和集合,但还有其他方法吗?

 global Set set

rule "match multiple products"
  when $prod: Product(code=='PRD-MERCH') from productList
  then
  System.out.println('Matched Products');
  set.add($prod); 
end

【问题讨论】:

    标签: drools rules rule-engine


    【解决方案1】:

    首先,让我告诉你,你使用的from productList 看起来已经很可疑了。 productList 是全球性的吗?

    现在,回到您的问题,如果您对所有匹配的 Product 事实感兴趣,您可以使用 collect 模式:

    rule "match multiple products"
    when 
      $prods: List(size > 0) from collect (
        Product(code=='PRD-MERCH') from productList
      )
    then
      System.out.println("Matched Products"+ $prods); 
    end
    

    希望对你有帮助,

    【讨论】:

    • 谢谢埃斯特班。是 productList 是一个全球性的
    猜你喜欢
    • 2018-10-04
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 2011-11-15
    • 2018-10-30
    相关资源
    最近更新 更多