Commit 62b25f54 authored by Casey Duncan's avatar Casey Duncan

Lazified computing the normalized score on text index search results. This can...

Lazified computing the normalized score on text index search results. This can shave seconds off search times when you get a lot of results
parent a1ee9940
...@@ -487,15 +487,25 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -487,15 +487,25 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# it, compute the normalized score, and Lazify it. # it, compute the normalized score, and Lazify it.
rset = rs.byValue(0) # sort it by score rset = rs.byValue(0) # sort it by score
max = float(rset[0][0]) max = float(rset[0][0])
rs = []
# XXX Ugh, this is really not as lazy as it could be # Here we define our getter function inline so that
# XXX This should be changed to a lazily computed # we can conveniently store the max value as a default arg
# XXX attribute since it is not always needed # and make the normalized score computation lazy
for score, key in rset: def getScoredResult(item, max=max, self=self):
# compute normalized scores """
rs.append((int(100. * score / max), score, key)) Returns instances of self._v_brains, or whatever is passed
append(LazyMap(self.__getitem__, rs)) 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'): elif sort_index is None and not hasattr(rs, 'values'):
# no scores? Just Lazify. # no scores? Just Lazify.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment