multi-column sort with ZCatalog
Hello all, I have a simple ZCatalog query with a sort_on and sort_order being passed to it. Is there any way I can do the sort on multiple columns? This seems like an important feature. I've heard that is not possible, but I'm wondering if I am just missing something/getting wrong info. I'm already looking into the Generic Sort External Method, but I'm wondering if there is some other way to do this? Thanks, ~Mark
--On Dienstag, 13. Mai 2003 8:23 Uhr -0400 Mark Nenadov <mark@freelance-developer.com> wrote:
Hello all,
I have a simple ZCatalog query with a sort_on and sort_order being passed to it.
Is there any way I can do the sort on multiple columns? This seems like an important feature. I've heard that is not possible, but I'm wondering if I am just missing something/getting wrong info.
I'm already looking into the Generic Sort External Method, but I'm wondering if there is some other way to do this?
you can use sequence.sort() to perform multi-column sorting on the resultset. -aj
Andreas Jung wrote:
Is there any way I can do the sort on multiple columns? This seems like an important feature. I've heard that is not possible, but I'm wondering if I am just missing something/getting wrong info.
ZCatalog doesn't support it, and I would agree that it's one that's very important and is missing :-(
you can use sequence.sort() to perform multi-column sorting on the resultset.
Yes, but surely it would be more efficient if ZCatalog did this internally and used some BTree magic to help... cheers, Chris
Here is recipe for a python script that may help. def multiSort(objects=None): """ Sort a list of objects by one or more attributes """ if objects is None: objects = [] return objects results = [] sort_field = ['field1', 'field2', 'field3'] for object in objects: row = [getattr(object, attr) for attr in sort_field] row.append(object) results.append(tuple(row)) results.sort() return [row[-1] for row in results] On Tue, 2003-05-13 at 08:23, Mark Nenadov wrote:
Hello all,
I have a simple ZCatalog query with a sort_on and sort_order being passed to it.
Is there any way I can do the sort on multiple columns? This seems like an important feature. I've heard that is not possible, but I'm wondering if I am just missing something/getting wrong info.
I'm already looking into the Generic Sort External Method, but I'm wondering if there is some other way to do this?
Thanks, ~Mark
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Michael Long <mlong@datalong.com>
Mark Nenadov wrote at 2003-5-13 08:23 -0400:
I have a simple ZCatalog query with a sort_on and sort_order being passed to it.
Is there any way I can do the sort on multiple columns? This seems like an important feature. I've heard that is not possible, but I'm wondering if I am just missing something/getting wrong info.
I'm already looking into the Generic Sort External Method, but I'm wondering if there is some other way to do this?
Others told you how to sort with "sequence.sort" and in a Python script. Some time ago, I posted a code snipped that provides sorting code for ZCatalog directly (--> archives). Maybe, this code will be integrated in Zope 2.7. It would not be trivial to integrate it yourself in Zope 2.6, however. Dieter
Dieter Maurer wrote:
Some time ago, I posted a code snipped that provides sorting code for ZCatalog directly (--> archives). Maybe, this code will be integrated in Zope 2.7.
Have you got a direct link? I'd be verymuch up for integrating this if you don't mind helping out if I get stuck... cheers, Chris
Chris Withers wrote at 2003-5-14 10:46 +0100:
Dieter Maurer wrote:
Some time ago, I posted a code snipped that provides sorting code for ZCatalog directly (--> archives). Maybe, this code will be integrated in Zope 2.7.
Have you got a direct link?
No. I would need to search (in the same way you would ;-) ). Search for "sortSpecs". Wait a bit: I think, I optimized the function a bit in the meantime. I attach it again.
I'd be verymuch up for integrating this if you don't mind helping out if I get stuck...
I posted it precisely because you wrote you were interested. I case of problems I would try to help: While I wrote integration would not be trivial this has not been meant for you :-) The most difficult part is to design a good API. The posted code has one but it is incompatible with the current "searchResults" API. Once the API is settled, the posted function could be used almost directly (with an API adapter as intermediary). Dieter
participants (5)
-
Andreas Jung -
Chris Withers -
Dieter Maurer -
Mark Nenadov -
Michael Long