<br>&nbsp;&nbsp; No single simple answer here. You need to check what would better fit your use case. <br>&nbsp;&nbsp; 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>&nbsp;&nbsp; No really &quot;clean&quot; way I can think about, but a few possible options (haven&#39;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">&nbsp;&nbsp; eventList : LinkedList( $size : size &gt;= 5 ) from collect( Event(text matches &quot;.*rule5.*&quot;<font size="2"> ))  <br>  </font><b><font color="#960000" size="2">
then<br>&nbsp;&nbsp; for( int i = 0; i &lt; $size/5; i++ )<br></font></b></div></font></font><font size="2"><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(<font color="#008000" size="2">&quot;rule5 is fired &quot;</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">&nbsp;&nbsp; eventList : LinkedList( size &gt;= 5 ) from collect( Event(text matches &quot;.*rule5.*&quot;, processed == false<font size="2"> ))  <br>
  </font><b><font color="#960000" size="2">then<br></font></b><font><font size="2">&nbsp;&nbsp; System.out.println(<font color="#008000" size="2">&quot;rule5 is fired &quot;</font><font size="2"> + eventList.size());</font>  <br>
</font></font><b><font color="#960000" size="2">
&nbsp;&nbsp; for( int i = 0; i &lt; 5; i++ ) {<br><span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.setProcessed( true );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; update( e ); <br></span>
</font></b></div></font></font><font size="2"><div>&nbsp;&nbsp; }<br>
</div></font>end<br>
<br>2. Retract used facts:<br>
<br>
<div>when</div>

<font size="2"><font size="2">    <div align="left">&nbsp;&nbsp; eventList : LinkedList( size &gt;= 5 ) from collect( Event(text matches &quot;.*rule5.*&quot;<font size="2"> ))  <br>
  </font><b><font color="#960000" size="2">then<br></font></b><font><font size="2">&nbsp;&nbsp; System.out.println(<font color="#008000" size="2">&quot;rule5 is fired &quot;</font><font size="2"> + eventList.size());</font>  <br>
</font></font><b><font color="#960000" size="2">
&nbsp;&nbsp; for( int i = 0; i &lt; 5; i++ ) {<br>
<span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retract( e ); <br>
</span>
</font></b></div></font></font><font size="2"><div>&nbsp;&nbsp; }<br>
</div></font>end<br>

<br>&nbsp;&nbsp;&nbsp;
Hope it helps.<br><br>&nbsp;&nbsp;&nbsp; Edson<br><span class="gmail_quote"></span><br><div><span class="gmail_quote">2007/8/10, Anh Vuong &lt;<a href="mailto:anhtvuong@yahoo.com">anhtvuong@yahoo.com</a>&gt;:</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&#39;d like to use keyword collect to do my filtering but its behaviour confused me, please advise. I greatly appreciate your help.</div>  <div>&nbsp;</div>  <div>Problem 1:</div>  <div>&nbsp;</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">&quot;.*rule5.*&quot;</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">&quot;rule5 is fired &quot;
</font><font size="2"> + eventList.size());</font>  <div><font size="2"></font>&nbsp;</div>  <div><font size="2">I still do not see&nbsp;any log msg after adding 5+ events. Is something wrong with my rule?</font></div>  <div>&nbsp;</div>
  <div>Problem 2:</div>  <div>&nbsp;</div>  <div>when</div>  <div>event: Event(text matches <font color="#008000" size="2">&quot;.*rule5.*&quot;</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">&quot;rule5 is fired &quot;</font><font size="2"> + eventList.size());</font>  <div>&nbsp;</div>  <div><font size="2">After adding 5 events, I see&nbsp;5 log msg instead of one as I&#39;d expect.
</font></div>  <div>If I add more events, I will see more log. How do I tell LHS&nbsp; 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>&nbsp;</div>  <div>Thanks,</div><span class="sg">  <div>-av</div></span><span class="ad">  <div><font size="2">&nbsp;</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&#39;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>&nbsp;&nbsp;Edson Tirelli<br>&nbsp;&nbsp;Software Engineer - JBoss Rules Core Developer<br>&nbsp;&nbsp;Office: +55 11 3529-6000<br>&nbsp;&nbsp;Mobile: +55 11 9287-5646<br>&nbsp;&nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">
www.jboss.com</a>