Don't be too keen on using "from" in connection with queries. The simple reason is that queries return nothing but what rules can do just as well.
Thus, getting all pairs of Person's and Restaurant's with matching "food" and "zipcode", the straightforward LHS would be p:Person( $favFood : favouriteFood, $zip : address.zipcode ) r: Restaurant( food == $favFood, postcode == $zip ) "from" is required if the objects aren't facts but, for instance, elements in a collection contained in a fact. So, if you have Restaurants only as a List<Restaurant> in a (say) City object, you would write p:Person( $favFood : favouriteFood, $zip : address.zipcode ) c: City( zipcodeSet contains $zip ) # a person's home town r: Restaurant( food == $favFood, postcode == $zip ) from c.restaurantList assuming that a (biggish) City typically has many zipcodes. -W On 28 July 2010 15:06, <[email protected]> wrote: > Hello list, > > I'm using Drools.5.0.1 and I am trying to comprehend how to used the > "from" keyword over a named query. > > I've googled this: > http://blog.athico.com/2007/06/chained-from-accumulate-collect.html > > where it states: > > p : Person( ) > Restaurant( food == p.favouriteFood ) > from hs.getNamedQuery( "list restaurants by postcode" ) > .setProperties( [ "postcode" : p.address.zipcode ] ) > .list() > > If I understand the above correctly, the "hs.getNamedQuery" returns > "Restaurant" objects using values from "Person" object. > > There are a couple of issues that I would like to resolve. > > Where and how is the "hs" object in "hs.getNamedQuery" statement is declared? > > If the "Person" object itself is the result of a NamedQuery, could the > above statement be rewritten as: > > p : Person( ) from ps.getNamedQuery("return list of persons") > Restaurant( food == p.favouriteFood ) > from hs.getNamedQuery( "list restaurants by postcode" ) > .setProperties( [ "postcode" : p.address.zipcode ] ) > .list() > > Thank you for your time. > -Stathis > > PS: Please take note that this is a newbie (in Drools) speaking. > > > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users > _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
