Hi Tomas, On Wed, Apr 22, 2009 at 09:59:07AM +0100, Tomas Hlavaty wrote: > > : (filter '((This) (= *D (: doc))) (collect 'usr '+Pat *U)) > > Yes, that's what I wanted. I thought it was possible to avoid > collecting the whole list constraining the search space before > collecting the values.
If the list returned by 'collect' is possibly rather long, there are two better methods: 1. You could use the Pilog functions 'pilog' or 'solve' and 'select' (pilog (quote @U *U @D *D (select (@Pat) ((usr +Pat @U) (doc +Pat @D)) (same @U @Pat usr) (same @D @Pat doc) ) ) (.. do something with the value of '@Pat' ...) ) or (solve @U *U @D *D (select (@Pat) ((usr +Pat @U) (doc +Pat @D)) (same @U @Pat usr) (same @D @Pat doc) ) ) -> returns a list 'select' is more efficient than a 'collect' in combination with 'filter', as it traverses the search trees more intelligently. 2. The most efficient way is to use an '+Aux' key. This generates a combined key in addition to the two indexes for 'usr' and 'doc'. (class +Pat +Entity) (rel doc (+Ref +Link) NIL (+Doc)) (rel usr (+Aux +Ref +Link) (doc) NIL (+Usr)) This will cause the 'usr' index to hold combinations of 'usr' and 'doc'. You can then find all matching hits directly with : (collect 'usr '+Pat (list *U *D)) but also still use the "normal" way : (collect 'usr '+Pat *U) Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe