[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog/tests - testCatalog.py:1.19

Casey Duncan casey@zope.com
Thu, 5 Dec 2002 16:17:11 -0500


Update of /cvs-repository/Zope/lib/python/Products/ZCatalog/tests
In directory cvs.zope.org:/tmp/cvs-serv30520/tests

Modified Files:
	testCatalog.py 
Log Message:
Major refactor of the catalog search engine centered around optimizing sort by index operations. The resulting code greatly outperforms the previous version and uses less memory.

Exposed a new ZCatalog method "search" which has a better interface for programmatic searches. Updated documentation as well.

Implemented a sort limit option which allows you to inform the catalog that you are only interested in a certain number of results. In the common case this allows the ZCatalog machinery to use a different sorting algorithm (N-Best) which scales much better then a full sort.

Also more tightly integrated the merge option which allows you to tell the catalog that you would like raw and unsorted intermediate results returned rather than sorted and lazified results. This can be used to efficiently merge search results across multiple catalogs.


=== Zope/lib/python/Products/ZCatalog/tests/testCatalog.py 1.18 => 1.19 ===
--- Zope/lib/python/Products/ZCatalog/tests/testCatalog.py:1.18	Wed Aug 28 13:08:50 2002
+++ Zope/lib/python/Products/ZCatalog/tests/testCatalog.py	Thu Dec  5 16:17:08 2002
@@ -157,6 +157,13 @@
         testNum = str(self.upper - 3) 
         data = self._catalog.getIndexDataForUID(testNum)
         assert data['title'][0] == testNum
+        
+    def testSearch(self):
+        query = {'title': ['5','6','7']}
+        sr = self._catalog.searchResults(query)
+        self.assertEqual(len(sr), 3)
+        sr = self._catalog.search(query)
+        self.assertEqual(len(sr), 3)
 
 class TestCatalogObject(unittest.TestCase):
     def setUp(self):
@@ -346,6 +353,11 @@
         # set is much larger than the sort index.
         a = self._catalog(sort_on='att1')
         self.assertEqual(len(a), self.upper)
+    
+    def testSortLimit(self):
+        a = self._catalog(sort_on='num', sort_limit=10)
+        self.assertEqual(a[0].num, self.upper - 1)
+        self.assertEqual(a.actual_result_count, self.upper)
 
 class objRS(ExtensionClass.Base):