No single simple answer here. You need to check what would better fit your use case.
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.
No really "clean" way I can think about, but a few possible options (haven't executed them, but shall work):
1. Simply execute the actions multiple times in the consequence:
wheneventList : LinkedList( $size : size >= 5 ) from collect( Event(text matches ".*rule5.*" ))
then
for( int i = 0; i < $size/5; i++ )System.out.println("rule5 is fired " + eventList.size ());end
2. Flag used facts:
wheneventList : LinkedList( size >= 5 ) from collect( Event(text matches ".*rule5.*", processed == false ))
then
System.out.println("rule5 is fired " + eventList.size());
for( int i = 0; i < 5; i++ ) {
Event e = (Event) eventList.get ( i );
e.setProcessed( true );
update( e );}end
2. Retract used facts:
wheneventList : LinkedList( size >= 5 ) from collect( Event(text matches ".*rule5.*" ))
then
System.out.println("rule5 is fired " + eventList.size());
for( int i = 0; i < 5; i++ ) {
Event e = (Event) eventList.get( i );
retract( e );}end
Hope it helps.
Edson
2007/8/10, Anh Vuong <anhtvuong@yahoo.com>:Hi,I'd like to use keyword collect to do my filtering but its behaviour confused me, please advise. I greatly appreciate your help.Problem 1:wheneventList : LinkedList(size == 5)from collect( Event(text matches".*rule5.*" )) thenSystem.out.println("rule5 is fired " + eventList.size());I still do not see any log msg after adding 5+ events. Is something wrong with my rule?Problem 2:whenevent: Event(text matches ".*rule5.*" ))eventList : LinkedList(size == 5)from collect( Event(text == event.text)thenSystem.out.println("rule5 is fired " + eventList.size());After adding 5 events, I see 5 log msg instead of one as I'd expect.If I add more events, I will see more log. How do I tell LHS to reset the count from 0.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.Thanks,-av
Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com _______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users