[Zope-CVS] CVS: Products/ZCTextIndex/tests - test_index.py:1.1.2.5

Fred L. Drake, Jr. fdrake@acm.org
Tue, 30 Apr 2002 18:03:25 -0400


Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv24661/lib/python/Products/ZCTextIndex/tests

Modified Files:
      Tag: TextIndexDS9-branch
	test_index.py 
Log Message:
Add more tests of searching.
Make the SimpleLexicon not generate word IDs for unknown query terms.


=== Products/ZCTextIndex/tests/test_index.py 1.1.2.4 => 1.1.2.5 ===
 
     def termToWordIds(self, text):
-        return self.sourceToWordIds(text)
+        words = text.split()
+        wids = []
+        for word in words:
+            wid = self._words.get(word)
+            if wid is None:
+                continue
+            wids.append(wid)
+        return wids
 
 
 class Indexable:
@@ -124,13 +131,25 @@
             self.assertEqual(len(map), 1)
             self.assert_(map.has_key(DOCID))
 
-    def test_simple_query(self):
-        doc = MethodIndexable('not the same document')
-        self.index.index_object(1, doc)
+    def test_simple_query_oneresult(self):
+        self.index.index_object(1, MethodIndexable('not the same document'))
         results = self.index.search("document")
         self.assertEqual(len(results), 1)
         self.assert_(results.has_key(1))
 
+    def test_simple_query_noresults(self):
+        self.index.index_object(1, MethodIndexable('not the same document'))
+        results = self.index.search("frobnicate")
+        self.assertEqual(len(results), 0)
+
+    def test_query_oneresult(self):
+        self.index.index_object(1, Indexable(
+            'not the same document'))
+        self.index.index_object(2, MethodIndexable(
+            'something about something else'))
+        results = self.index.search("document")
+        self.assertEqual(len(results), 1)
+        self.assert_(results.has_key(1))
 
 def test_suite():
     return makeSuite(IndexTest)