Take a look at the <i>AgendaEventListener</i>. 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.<br><br><div class="gmail_quote">
On Wed, Aug 19, 2009 at 4:27 AM, KDR <span dir="ltr">&lt;<a href="mailto:dr.soprano@neverbox.com">dr.soprano@neverbox.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi, ta very much everyone for the help so far.<br>
<br>
Another question - how to sort by number of matches please?<br>
<br>
Say I have objects A, B, C and D and rules 1 to 5. Each object can match<br>
each rule independently e.g. A can match rule 1 and 2, B might match all<br>
rules 1 to 5, C might match none, D rules 3 and 4 etc.<br>
<br>
I need to rank them and then print out info about them in order of number of<br>
matches, with an indication of which rules matched, i.e. print info on B<br>
before A but nothing at all on C, etc.<br>
<br>
In Java I&#39;d probably do it by having, as a global variable, a map where the<br>
key is the name or ID field of the object and the value is an arraylist<br>
which gets added to in the consequence (with a string about what kind of<br>
match it was i.e. which rule was matched) whenever there&#39;s a match on a rule<br>
for that object. Then sort it by descending length of the arraylists.<br>
<br>
There has to be a better and more elegant way of doing it in Drools,<br>
probably involving collecting info on the matches and then sorting them, but<br>
I can&#39;t think what or how.<br>
<br>
Does anyone have any thoughts or suggestions please?<br>
<br>
Many thanks in advance.<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://www.nabble.com/Collecting---sorting-by-the-number-of-matches-tp25039921p25039921.html" target="_blank">http://www.nabble.com/Collecting---sorting-by-the-number-of-matches-tp25039921p25039921.html</a><br>

Sent from the drools - user mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>