[Zope-CMF] Sorting on a TextIndex for CMFTopic
Tres Seaver
tseaver@zope.com
17 Dec 2002 09:28:36 -0500
On Wed, 2002-12-11 at 13:49, Francis Barnhart wrote:
> In researching an error I received while attempting to sort topic
> results by Title I found that index types of TextIndex cannot be
> sorted. Is there a current work around for this problem? If not, does
> it seems reasonable to add a FieldIndex, SortTitle for instance, that
> is equal to the Title (before indexing)? If so, I'd appreciate some
> guidance.
One way to do this, which will work on any Zope, would be:
1. Define a PythonScript, 'Title_for_sort' (or whatever), in the
'custom' folder of your skins tool::
## Script (Python) "Title_for_sort"
##parameters=
##title=Return the title, to be indexed for sorting purposes
return context.Title()'
2. Add a FieldIndex to your catalog, with the same ID as the
PythonScript. Re-index the catalog (or at least the new index).
3. Query the catalog, passing the new index as the sort index. E.g.::
<div tal:repeat="result python:here.portal_catalog(
sort_on='Title_for_sort' ) # add criteria
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com