[Zope-Coders] Sorting on Textindexes

Andreas Jung Andreas Jung <andreas@andreas-jung.com>
Mon, 12 May 2003 18:21:01 +0200


Chris Withers came up with a case where it is impossible to sort by the 
ranking of a ZCTextIndex query
when other indexes are involved (e.g. you perfrom a search on 
SearchableText in combination
with a range search on a DateTime field). The underlaying problem is that 
the Catalog check for
the keyForDocument() method of an index to obtain a value from an index to 
be used for sorting.
This approach is ok for FieldIndexes but it sucks for text indexes because 
the relevant information
is part of the result set and can not be retrieved from the index itself.

What about the following solution: indexes return either a sequence of 
docids or a mapping
docid -> ranking.  We could introduce a tiny resultset class that could be 
used to wrap
the the mapping docid-> ranking. Of course this class would have a method 
keyForDocument().
In the sorting phase, the Catalog would either check for the standard 
sequence/mapping of
docids or for the resultset class and call keyForDocument() either on the 
index or on the result
set. This approach has one drawback: it is necessary to store the 
resultsets of the text indexes
because at the moment they are lost after performing the intersection of 
the docids set from the
different subqueries.

Andreas