[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog - Catalog.py:1.90
Casey Duncan
casey@zope.com
Tue, 16 Jul 2002 17:51:27 -0400
Update of /cvs-repository/Zope/lib/python/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv23369
Modified Files:
Catalog.py
Log Message:
Lazified computing the normalized score on text index search results. This can shave seconds off search times when you get a lot of results
=== Zope/lib/python/Products/ZCatalog/Catalog.py 1.89 => 1.90 ===
# it, compute the normalized score, and Lazify it.
rset = rs.byValue(0) # sort it by score
max = float(rset[0][0])
- rs = []
- # XXX Ugh, this is really not as lazy as it could be
- # XXX This should be changed to a lazily computed
- # XXX attribute since it is not always needed
- for score, key in rset:
- # compute normalized scores
- rs.append((int(100. * score / max), score, key))
- append(LazyMap(self.__getitem__, rs))
+ # Here we define our getter function inline so that
+ # we can conveniently store the max value as a default arg
+ # and make the normalized score computation lazy
+ def getScoredResult(item, max=max, self=self):
+ """
+ Returns instances of self._v_brains, or whatever is passed
+ into self.useBrains.
+ """
+ score, key = item
+ r=self._v_result_class(self.data[key])\
+ .__of__(self.aq_parent)
+ r.data_record_id_ = key
+ r.data_record_score_ = score
+ r.data_record_normalized_score_ = int(100. * score / max)
+ return r
+
+ # Lazify the results
+ append(LazyMap(getScoredResult, rset))
elif sort_index is None and not hasattr(rs, 'values'):
# no scores? Just Lazify.