'this' Drools 规则左侧的等效关键字

'this' equivalent keyword in Drools rule left-hand side

给定一个配置 class Config,其中包含一个属性 excludeShifts,它是 class Shift 的列表,是否有像 'this' 这样的关键字表示匹配中的当前对象过程?例如,

rule "Match but not if excluded"
  when
     $config : Config(...)  // additional matching criteria deleted

     $shift : Shift(this not memberOf $config.excludeShifts,
                    ...     // additional criteria deleted
                    )
     ... // additional criteria deleted
  then
     ...
end

我认识到在功能上我可以颠倒顺序以实现此匹配:

   $shift : Shift()
   $config : Config(excludeShifts not contains $shift
                   )

this 是一个公认的关键字,它的使用方式与您指定的方式相同,作为对当前正在评估的对象的引用。

一些例子:

// An even integer in working memory
$even: Integer( this % 2 == 0 )

// A string with a specific value
$animal: String(this in ("cat", "dog", "fish"))

// A value from a map
Map( $value: this['key'] )

您的示例与您编写的一样有效。

rule "Match but not if excluded"
when
  $config : Config($excluded: excludedShifts)
  $shift : Shift(this not memberOf $excluded)
then
end

我浏览了 documentation,但我没有看到 this 是否曾经作为关键字被调用过(虽然承认它有点难以搜索。)它用于几个示例,例如,在 forall 运算符示例代码中。正如 Esteban 在评论中所建议的那样,欢迎您打开错误报告或提交文档修复以纠正此疏忽。