<div>Yes Edson, I tried with count and sum. Both seems to be working fine.</div>
<div> </div>
<div>But with the test case, the Criteria for query also needs to be inserted in addition to the query and data objects like shown below:</div>
<div> </div><font size="2">
<p align="left">Query query = </p></font><b><font color="#7f0055" size="2"><font color="#7f0055" size="2">new</font></font></b><font size="2"> Query(1);
<p align="left">query.add(</p></font><b><font color="#7f0055" size="2"><font color="#7f0055" size="2">new</font></font></b><font size="2"> Criteria(query, </font><font color="#2a00ff" size="2"><font color="#2a00ff" size="2">&quot;c2&quot;</font></font><font size="2">, </font><font color="#2a00ff" size="2"><font color="#2a00ff" size="2">&quot;bas&quot;</font></font><font size="2">));
<p align="left">ksession.insert(query);</p>
<p align="left"></p></font><b><font color="#7f0055" size="2"><font color="#7f0055" size="2">for</font></font></b><font size="2">(Criteria c : query) {
<p align="left">ksession.insert(c);</p>
<p>}</p>
<p></p></font> 
<div> </div>
<div>Is it possible to avoid them.</div>
<div> </div>
<div>Thanks,</div>
<div>cabear</div>
<div><br><br></div>
<div class="gmail_quote">2009/11/8 Edson Tirelli <span dir="ltr">&lt;<a href="mailto:ed.tirelli@gmail.com">ed.tirelli@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>   Why not use count() accumulate function? ;) 
<div class="im"><br><br>from accumulate( Criteria( this memberOf d, this memberOf q ),<br></div>                           count(1) )<br><br>   Edson 
<div>
<div></div>
<div class="h5"><br><br>
<div class="gmail_quote">2009/11/8 Greg Barton <span dir="ltr">&lt;<a href="mailto:greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">In this case the accumulate clause is maintaining a counter (total) that&#39;s incremented whenever a Criteria is detected that is contained in both the Data and Query object matched in the rule.  So:<br>
<br># Find Criteria that are contained in both the Data and Query<br>
<div>from accumulate( Criteria( this memberOf d, this memberOf q ),<br></div># Initialize the counter to 0<br> init( int total = 0; ),<br># Increment when the above condition is  matched<br> action( total ++; ),<br># Decrement if a matched Criteria now fails to match<br>
 reverse( total --; ),<br># return the total when all known Criteria are matched<br> result( total ) )<br>
<div><br>--- On Sun, 11/8/09, Wishing Carebear &lt;<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>&gt; wrote:<br><br>&gt; From: Wishing Carebear &lt;<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>&gt;<br>
</div>&gt; Subject: Re: [rules-users] some pointers for solution<br>&gt; To: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>&gt;<br>&gt; Date: Sunday, November 8, 2009, 11:39 AM<br>

<div>
<div></div>
<div>&gt; Hi Greg:<br>&gt; I&#39;m trying to understand your first<br>&gt; solution.<br>&gt;  <br>&gt; Ran the project and it works fine. If possible could<br>&gt; you explain me little bit on :<br>&gt;<br>&gt; from accumulate( Criteria( this memberOf d,<br>
&gt; this memberOf q ),<br>&gt; init( int total = 0; ),<br>&gt; action( total ++; ),<br>&gt; reverse( total --; ),<br>&gt; result( total ) )<br>&gt;  <br>&gt;  <br>&gt; Thanks,<br>&gt; cabear<br>&gt;<br>&gt;<br>&gt; 2009/11/8 Greg Barton &lt;<a href="mailto:greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>&gt;<br>
&gt;<br>&gt; There are a couple of<br>&gt; ways to do this.  I&#39;m sure there&#39;s a bit more clean<br>&gt; way than the example I&#39;m providing, but this should get<br>&gt; you in the right direction.  It&#39;s not 100% rules,<br>
&gt; because it involves a bit of java collections trickery. (See<br>&gt; attached project, collection_DroolsCriteriaMatch.tar.gz)<br>&gt;<br>&gt;<br>&gt; The heart of it is a single rule:<br>&gt;<br>&gt; rule &quot;Match&quot;<br>
&gt;  when<br>&gt;    d : Data()<br>&gt;    q : Query( size &lt;= d.size )<br>&gt;    Number( intValue == q.size )<br>&gt;    from accumulate(<br>&gt;      Criteria( this memberOf d, this memberOf q ),<br>&gt;<br>&gt;      init( int total = 0; ),<br>
&gt;      action( total ++; ),<br>&gt;      reverse( total --; ),<br>&gt;      result( total )<br>&gt;    )<br>&gt;  then<br>&gt;    System.out.println(&quot;Match: &quot; + d + &quot;<br>&gt; and &quot; + q) ;<br>&gt; end<br>
&gt;<br>&gt; The Data object holds data to be queried, Query objects are<br>&gt; asserted to match the Data, and Criteria objects can be<br>&gt; contained in either. (With the aforementioned collections<br>&gt; trickery that if a Criteria is contained in a Query it can<br>
&gt; be found in a Data object, but the reverse isn&#39;t true.<br>&gt;  See the Query.contains(Object) method for how that&#39;s<br>&gt; implemented.)<br>&gt;<br>&gt;<br>&gt; So the rule above basically says &quot;There&#39;s a Data<br>
&gt; object, and all of the Query objects Criteria are contained<br>&gt; in the Data object.&quot;<br>&gt;<br>&gt; There&#39;s an alternate way of doing this using eval and a<br>&gt; bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz<br>
&gt; project attached.  This one&#39;s probably not optimal,<br>&gt; though, as it&#39;s basically a brute force check of all<br>&gt; Data objects against the asserted Query.<br>&gt;<br>&gt;<br>&gt; I tried for a while to get a solution working with<br>
&gt; different criteria types from both Data and Query objects<br>&gt; being asserted into working memory, but I couldn&#39;t get<br>&gt; the accumulate syntax right.  Anyone know of a way to do<br>&gt; that? (I figure that would get a &quot;pure rules&quot;<br>
&gt; solution.)<br>&gt;<br>&gt;<br>&gt; --- On Sat, 11/7/09, Wishing Carebear &lt;<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>&gt;<br>&gt; wrote:<br>&gt;<br>&gt; &gt; From: Wishing Carebear &lt;<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>&gt;<br>
&gt;<br>&gt; &gt; Subject: [rules-users] some pointers for solution<br>&gt; &gt; To: <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>&gt; &gt; Date: Saturday, November 7, 2009, 10:19 PM<br>
&gt;<br>&gt;<br>&gt;<br>&gt; &gt; Hello:<br>&gt; &gt; There are n selection criteria from s1 .. sn for each<br>&gt; &gt; item i1.. in. Each item can have a subset of criteria<br>&gt; which<br>&gt; &gt; applies to them.<br>
&gt; &gt;  <br>&gt; &gt; The end user, can choose a subset of criteria like c1<br>&gt;<br>&gt; &gt; and c5 and only the item that has c1 and c5 valid<br>&gt; should be<br>&gt; &gt; returned. For example: if item i1 and i2 have<br>
&gt; criterias<br>&gt; &gt; valid for c1, c2, c5, c6, c8 since the request is only<br>&gt; for<br>&gt; &gt; criteria c1 and c5, i1 and i2 must be returned.<br>&gt;<br>&gt; &gt;<br>&gt; &gt;  <br>&gt; &gt; Is it possible to write a rule using drools for this<br>
&gt; &gt; requirement.<br>&gt; &gt;  <br>&gt; &gt; Thanks for your help and time,<br>&gt; &gt; cabear<br>&gt; &gt;<br>&gt; &gt; -----Inline Attachment Follows-----<br>&gt;<br>&gt; &gt;<br>&gt; &gt; _______________________________________________<br>
&gt; &gt; rules-users mailing list<br>&gt; &gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt;      <br>&gt; _______________________________________________<br>&gt; rules-users mailing list<br>&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; -----Inline Attachment Follows-----<br>
&gt;<br>&gt; _______________________________________________<br>&gt; rules-users mailing list<br>&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br><br><br><br><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</div></div></blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss by Red Hat @ <a href="http://www.jboss.com/" target="_blank">www.jboss.com</a><br>
</font><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>
<br></blockquote></div><br>