<br> No single simple answer here. You need to check what would better fit your use case. <br> The thing is: it is not possible to limit the number of matches to a collect statement... all matching instances WILL match it and be collected.
<br><br> No really "clean" way I can think about, but a few possible options (haven't executed them, but shall work):<br><br>1. Simply execute the actions multiple times in the consequence:<br><br><div>when
</div><font size="2"><font size="2"> <div align="left"> eventList : LinkedList( $size : size >= 5 ) from collect( Event(text matches ".*rule5.*"<font size="2"> )) <br> </font><b><font color="#960000" size="2">
then<br> for( int i = 0; i < $size/5; i++ )<br></font></b></div></font></font><font size="2"><div> System.out.println(<font color="#008000" size="2">"rule5 is fired "</font><font size="2"> + eventList.size
());</font> <br></div></font>end<br><br>2. Flag used facts:<br><br><div>when</div>
<font size="2"><font size="2"> <div align="left"> eventList : LinkedList( size >= 5 ) from collect( Event(text matches ".*rule5.*", processed == false<font size="2"> )) <br>
</font><b><font color="#960000" size="2">then<br></font></b><font><font size="2"> System.out.println(<font color="#008000" size="2">"rule5 is fired "</font><font size="2"> + eventList.size());</font> <br>
</font></font><b><font color="#960000" size="2">
for( int i = 0; i < 5; i++ ) {<br><span style="font-weight: bold;"> Event e = </span></font></b><font size="2"><font size="2"><b><font color="#960000" size="2"><span style="font-weight: bold;">(Event) eventList.get
( i );</span></font></b></font></font><b><font color="#960000" size="2"><span style="font-weight: bold;"></span><br><span style="font-weight: bold;"> e.setProcessed( true );<br> update( e ); <br></span>
</font></b></div></font></font><font size="2"><div> }<br>
</div></font>end<br>
<br>2. Retract used facts:<br>
<br>
<div>when</div>
<font size="2"><font size="2"> <div align="left"> eventList : LinkedList( size >= 5 ) from collect( Event(text matches ".*rule5.*"<font size="2"> )) <br>
</font><b><font color="#960000" size="2">then<br></font></b><font><font size="2"> System.out.println(<font color="#008000" size="2">"rule5 is fired "</font><font size="2"> + eventList.size());</font> <br>
</font></font><b><font color="#960000" size="2">
for( int i = 0; i < 5; i++ ) {<br>
<span style="font-weight: bold;"> Event e = </span></font></b><font size="2"><font size="2"><b><font color="#960000" size="2"><span style="font-weight: bold;">(Event) eventList.get( i );</span></font></b></font></font>
<b><font color="#960000" size="2"><span style="font-weight: bold;"></span><br>
<span style="font-weight: bold;"> retract( e ); <br>
</span>
</font></b></div></font></font><font size="2"><div> }<br>
</div></font>end<br>
<br>
Hope it helps.<br><br> Edson<br><span class="gmail_quote"></span><br><div><span class="gmail_quote">2007/8/10, Anh Vuong <<a href="mailto:anhtvuong@yahoo.com">anhtvuong@yahoo.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Hi,</div> <div>I'd like to use keyword collect to do my filtering but its behaviour confused me, please advise. I greatly appreciate your help.</div> <div> </div> <div>Problem 1:</div> <div> </div> <div>when
</div><font size="2"><font size="2"> <div align="left">eventList : LinkedList(size == 5)</div> <div align="left">from collect( Event(text matches </div></font><font color="#008000" size="2">".*rule5.*"</font><font size="2">
)) <div align="left"></div> <div align="left"></div></font><b><font color="#960000" size="2">then</font></b></font><font size="2"> <div>System.out.println(</div></font><font color="#008000" size="2">"rule5 is fired "
</font><font size="2"> + eventList.size());</font> <div><font size="2"></font> </div> <div><font size="2">I still do not see any log msg after adding 5+ events. Is something wrong with my rule?</font></div> <div> </div>
<div>Problem 2:</div> <div> </div> <div>when</div> <div>event: Event(text matches <font color="#008000" size="2">".*rule5.*"</font><font size="2"> ))</font></div><font size="2"><font size="2"> <div align="left">
eventList : LinkedList(size == 5)</div> <div align="left">from collect( Event(text == event.text)</div></font><font size="2"> <div align="left"></div> <div align="left"></div></font><b><font color="#960000" size="2">then
</font></b></font><font size="2"> <div>System.out.println(</div></font><font color="#008000" size="2">"rule5 is fired "</font><font size="2"> + eventList.size());</font> <div> </div> <div><font size="2">After adding 5 events, I see 5 log msg instead of one as I'd expect.
</font></div> <div>If I add more events, I will see more log. How do I tell LHS to reset the count from 0.</div> <div>Basically, I want to take 1 event out of 5 similar events (suppressing filtering). So if there are 10 similar events, my RHS should activate 2 times, not 10 times.
</div> <div> </div> <div>Thanks,</div><span class="sg"> <div>-av</div></span><span class="ad"> <div><font size="2"> </font></div><p>
</p><hr size="1">Ready for the edge of your seat?
<a href="http://us.rd.yahoo.com/evt=48220/*http://tv.yahoo.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Check out tonight's top picks</a> on Yahoo! TV.
<p></p></span><br>_______________________________________________<br>rules-users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org
</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br></blockquote></div>
<br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">
www.jboss.com</a>