[Zope3-checkins] CVS: Zope3/lib/python/Zope/TextIndex - TextIndexWrapper.py:1.5

Guido van Rossum guido@python.org
Thu, 5 Dec 2002 07:41:39 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/TextIndex
In directory cvs.zope.org:/tmp/cvs-serv17380

Modified Files:
	TextIndexWrapper.py 
Log Message:
Fix division by zero on globbing query.
Add unit tests for that, and for default values of batching parameters.

=== Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py:1.4	Wed Dec  4 13:41:56 2002
+++ Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py	Thu Dec  5 07:41:08 2002
@@ -68,8 +68,13 @@
         chooser.addmany(results.items())
         batch = chooser.getbest()
         batch = batch[start:]
-        qw = 1.0 * self.index.query_weight(tree.terms())
-        batch = [(docid, score/qw) for docid, score in batch]
+        if batch:
+            qw = self.index.query_weight(tree.terms())
+            # Hack to avoid ZeroDivisionError
+            if qw == 0:
+                qw = batch[0][1] or 1
+            qw *= 1.0
+            batch = [(docid, score/qw) for docid, score in batch]
         return batch, len(results)
 
     # Methods implementing IStatistics