How to keep track of multiple matches in drools

BreenDeen

I have a rule that fires many times for products that match my product code. How do I get all the products that have been matched? I know I can use a global and a set, but is there another way?

 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
Esteban Aliverti

First of all, let me tell you that the from productList you are using already looks suspicious. Is productList a global?

Now, going back to your question, if you are interested in all the Product facts that match, you can use a collect pattern:

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

Hope it helps,

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

XQuery basics - how to keep track of multiple variables?

How to keep track of multiple versions of assemblies?

How do I keep track of multiple objects in Javascript

How do I keep track of cards in hand with multiple lists in dictionary?

Keep track of multiple checkboxes react

How to keep the order of matches

How to keep track of "streaks" in the database?

How to keep track of players' rankings?

How to keep track of processed users?

How to keep track of retries in celery

How to keep track of objects in an Array?

How do you keep track of multiple properties of a string without traversing it multiple times?

Keep track of list values in multiple loops

keep track of multiple terminals from shell script

Prolog - Keep track of multiple sum counters

How to track multiple touches

How do I keep track of which icon is currently selected instead of multiple icons at a time

How can I keep track of record number across multiple json objects in PHP

R - reduce with merge and more than 2 suffixes (or: how to merge multiple dataframes and keep track of columns)

How to delegate threads to multiple servers and keep a track in which thread is on which server using Java

How can I start multiple vscode from c# and keep track of when they terminate?

How to save multiple dates in Firebase database so that admin can keep track of orders on a particular date

Keep lines with multiple matches from file grep

How to keep track of printed items in a for loop?

How to string together ConcatMaps and keep track of data

How to keep track of 'highlights' in OpenGL Image Viewer

How to keep track of event subscriptions for various events

How to keep track of the selected items in a RecyclerView in Android?

Angular - How to keep track of array of arrays in a FormGroup