[Zope-CVS] CVS: Products/FieldedTextIndex - index.py:1.4 test.py:1.3

Casey Duncan casey at zope.com
Thu Dec 11 22:27:59 EST 2003


Update of /cvs-repository/Products/FieldedTextIndex
In directory cvs.zope.org:/tmp/cvs-serv32290

Modified Files:
	index.py test.py 
Log Message:
Fix error when querying for a word that occurs in the index but not in the
fields search. Add test for this case.


=== Products/FieldedTextIndex/index.py 1.3 => 1.4 ===
--- Products/FieldedTextIndex/index.py:1.3	Wed Dec 10 01:13:40 2003
+++ Products/FieldedTextIndex/index.py	Thu Dec 11 22:27:58 2003
@@ -332,11 +332,7 @@
         search_fields = getattr(
             self.REQUEST, '_fielded_text_index_search_fields', None)
         N = float(self.document_count())  # total # of docs
-        try:
-            doclen = self._totaldoclen()
-        except TypeError:
-            # _totaldoclen has not yet been upgraded
-            doclen = self._totaldoclen
+        doclen = self._totaldoclen()
         meandoclen = doclen / N
         #K1 = self.K1
         #B = self.B
@@ -360,6 +356,8 @@
                     except KeyError:
                         pass # No docs for this field
                 w, d2f = weightedIntersection(d2f, multiunion(docsets), 1, 0)
+                if not d2f:
+                    continue
             idf = inverse_doc_frequency(len(d2f), N)  # an unscaled float
             result = IIBucket()
             score(result, d2f.items(), docid2len, idf, meandoclen)


=== Products/FieldedTextIndex/test.py 1.2 => 1.3 ===
--- Products/FieldedTextIndex/test.py:1.2	Wed Dec 10 01:13:40 2003
+++ Products/FieldedTextIndex/test.py	Thu Dec 11 22:27:58 2003
@@ -198,6 +198,13 @@
         results, used = self.index._apply_index(
             {'fields':{'query':'field', 'fields':['yertle', 'clyde']}})
         self.assertEqual(list(results.keys()), [2])
+    
+    def test_query_word_in_index_but_not_field(self):
+        self.index_one(1)
+        self.index_two(2)
+        results, used = self.index._apply_index(
+            {'fields':{'query':'izzy', 'fields':['title']}})
+        self.assertEqual(list(results.keys()), [])        
 
     def test_query_not_for_index(self):
         self.index_one(1)




More information about the Zope-CVS mailing list