Multiple sort keys for ZCatalog searching (was: RE: [Zope] Hardware for Zope + ZEO)
Dieter Maurer
dieter@handshake.de
Mon, 31 Mar 2003 21:25:01 +0200
--eZn+NsyD2j
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit
Chris Withers wrote at 2003-3-31 10:24 +0100:
> Dieter Maurer wrote:
> > I have code to extend ZCatalog's sorting capability to arbitrary many
> > sort keys.
> >
> > Maybe, we want something like this in the Zope core?
>
> Yes PLEASE!
>
> What does the code look like?
>
> Anything I can do to help?
Attached.
Dieter
--eZn+NsyD2j
Content-Type: application/x-python
Content-Description: Sort extension for ZCatalog
Content-Disposition: attachment;
filename="sortCatalog.py"
Content-Transfer-Encoding: base64
ZGVmIF9zb3J0KHJzLHNvcnRTcGVjcyk6CiAgJycnc29ydCByZXN1bHQgc2V0ICpycyogYWNj
b3JkaW5nIHRvICpzb3J0U3BlY3MqLgoKICAqc29ydFNwZWNzKiBpcyBhIHNlcXVlbmNlIG9m
IHBhaXJzICpzb3J0SW5kZXgqLCpzb3J0UmV2ZXJzZSouCiAgJycnCiAgaWYgbm90IHNvcnRT
cGVjczogcmV0dXJuIHJzCiAgbD0gW107IGFwcGVuZD0gbC5hcHBlbmQKICBzb3J0U3BlYz0g
c29ydFNwZWNzWzBdOyBzb3J0U3BlY3M9IHNvcnRTcGVjc1sxOl0KICBzb3J0SW5kZXgsIHNv
cnRSZXZlcnNlPSBzb3J0U3BlYwogICMgY29weSBjb2RlIGZyb20gIlpDYXRhbG9nLkNhdGFs
b2cuQ2F0YWxvZy5faW5kZXhlZFNlYXJjaCIKICBpZiBsZW4ocnMpID4gNCpsZW4oc29ydElu
ZGV4KToKICAgICMgcmVzdWx0IGxhcmdlIGNvbXBhcmVkIHRvICJzb3J0X2luZGV4IgogICAg
Zm9yIGssZG9jcyBpbiBzb3J0SW5kZXguaXRlbXMoKToKICAgICAgZG9jcz0gaW50ZXJzZWN0
aW9uKHJzLGRvY3MpCiAgICAgIG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