[Zope] ZCatalog: sorting on multiple indexes

Casey Duncan casey@zope.com
Thu, 12 Dec 2002 00:58:03 -0500


Can't currently be done at query time. However, you could populate a sort=
=20
index with a combo of the values you want to sort on, such as this python=
=20
script code:

return context.lastname + context.firstname

Put this in a Python script named LastFirst and add a matching field inde=
x and=20
reindex it. Now use that as your sort index and you'll sort on multiple=20
values.

If the values aren't addable, then you can also just index a tuple of=20
arbitrary length like:

return (context.attr1, context.attr2, context.attr3)

I have recently been working on the ZCatalog sorting code and it is possi=
ble=20
to add this capability for Zope 2.7. How do people feel about this? Would=
=20
many of you use it? I suppose one use would be grouping on reports.

Zope 2.7 will contain many different sorting algorithms, it is likely tha=
t=20
sorting on multiple keys will limit you to just a few possible algorithms=
=2E So=20
the above technique would still be useful for best performance, however i=
t is=20
much less flexible.

-Casey

On Wednesday 11 December 2002 09:04 am, Giuseppe Bonelli wrote:
> Hi all,
>=20
> this appears to be an old question, but I have not found any reply on t=
he=20
mailing list archives.
>=20
> Is there any trick to sort the results from ZCatalog on two or more ind=
exes=20
?
>=20
> TIA,
>=20
> --peppo=20