[Zope] multi-column sort with ZCatalog

Dieter Maurer dieter@handshake.de
Wed, 14 May 2003 20:00:08 +0200


--ZFCmr6eevh
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit

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

--ZFCmr6eevh
Content-Type: application/x-python
Content-Description: index based multisort
Content-Disposition: attachment;
	filename="multisort.py"
Content-Transfer-Encoding: base64

ZGVmIF9zb3J0KHJzLHNvcnRTcGVjcyk6CiAgJycnc29ydCByZXN1bHQgc2V0ICpycyogYWNj
b3JkaW5nIHRvICpzb3J0U3BlY3MqLgoKICAqc29ydFNwZWNzKiBpcyBhIHNlcXVlbmNlIG9m
IHBhaXJzICpzb3J0SW5kZXgqLCpzb3J0UmV2ZXJzZSouCiAgJycnCiAgaWYgbm90IHNvcnRT
cGVjczogcmV0dXJuIHJzCiAgbD0gW107IGFwcGVuZD0gbC5hcHBlbmQKICBzb3J0U3BlYz0g
c29ydFNwZWNzWzBdOyBzb3J0U3BlY3M9IHNvcnRTcGVjc1sxOl0KICBzb3J0SW5kZXgsIHNv
cnRSZXZlcnNlPSBzb3J0U3BlYwogICMgY29weSBjb2RlIGZyb20gIlpDYXRhbG9nLkNhdGFs
b2cuQ2F0YWxvZy5faW5kZXhlZFNlYXJjaCIKICB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