Take a look at the AgendaEventListener. It allows you to get callbacks for when a rule has fired. This would allow you to keep track of which rules fire along with the objects that caused it to fire.
Hi, ta very much everyone for the help so far.
Another question - how to sort by number of matches please?
Say I have objects A, B, C and D and rules 1 to 5. Each object can match
each rule independently e.g. A can match rule 1 and 2, B might match all
rules 1 to 5, C might match none, D rules 3 and 4 etc.
I need to rank them and then print out info about them in order of number of
matches, with an indication of which rules matched, i.e. print info on B
before A but nothing at all on C, etc.
In Java I'd probably do it by having, as a global variable, a map where the
key is the name or ID field of the object and the value is an arraylist
which gets added to in the consequence (with a string about what kind of
match it was i.e. which rule was matched) whenever there's a match on a rule
for that object. Then sort it by descending length of the arraylists.
There has to be a better and more elegant way of doing it in Drools,
probably involving collecting info on the matches and then sorting them, but
I can't think what or how.
Does anyone have any thoughts or suggestions please?
Many thanks in advance.
--
View this message in context: http://www.nabble.com/Collecting---sorting-by-the-number-of-matches-tp25039921p25039921.html
Sent from the drools - user mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users