[Zope] Combining 2 Catalog results while keeping sort_on and sort_order correct
Lea Smith
richandleacv@yahoo.com
Fri, 13 Sep 2002 13:19:38 +0100 (BST)
Hi,
(zope 2.5.1, python 2.1.3, testing on win2000)
A couple of areas of a site I am developing requires
the catalog to be quried twice and the results
combined.
What is the most eficient method to combine these
results while ensuring the complete results still
follow the sort_on and sort_order sent in the catalog
query?
I have tried two methods:
1.
Add the two results and re-sort the lot using
...
all_results.sort( lambda x,y: getattr(x, sortOn),
getattr(y, sortOn))
...
(sortOn passed in to the script)
2.
Find which results is the smallest and insert these
one by one into the larger results. (Similar code to
something I came across in the zope pyhton code on my
system, forget the name of it at the moment). Using
the following code to find the right place in the
larger results to insert the current item from smaller
results.
...
getattr(results[mid], sortOn) < getattr(y, sortOn)
...
Both methods are not very fast. Is there a better way
to do this?
Thanks for any help.
Richard
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com