[Zope-Checkins] CVS: Zope2 - Catalog.py:1.70.6.7

Andreas Jung andreas@digicool.com
Wed, 23 May 2001 15:23:48 -0400


Update of /cvs-repository/Zope2/lib/python/Products/ZCatalog
In directory yetix:/work/sandboxes/ajung-dropin-registry/lib/python/Products/ZCatalog

Modified Files:
      Tag: ajung-dropin-registry
	Catalog.py 
Log Message:
code cleanup,optimization



--- Updated File Catalog.py in package Zope2 --
--- Catalog.py	2001/05/23 16:37:47	1.70.6.6
+++ Catalog.py	2001/05/23 19:23:41	1.70.6.7
@@ -519,25 +519,36 @@
     
 ## Searching engine.  You don't really have to worry about what goes
 ## on below here...  Most of this stuff came from ZTables with tweaks.
+## But I worry about :-)
 
-    def _indexedSearch(self, args, sort_index, append, used):
+    def _indexedSearch(self, request , sort_index, append, used):
         """
         Iterate through the indexes, applying the query to each one.
         """
 
-        rs=None
-        data=self.data
+        rs   = None             # resultset
+        data = self.data
         
         if used is None: used={}
         for i in self.indexes.keys():
+
             index = self.indexes[i].__of__(self)
             if hasattr(index,'_apply_index'):
-                r=index._apply_index(args)
+
+                r = None
+
+                # Optimization: we check if there is some work for the index.
+                # 
+                if request.has_key(index.id) :
+                    if len(request[index.id])>0:
+                        r=index._apply_index(request)
+
                 if r is not None:
                     r, u = r
-                    for name in u:
-                        used[name]=1
+                    for name in u: used[name]=1
                     w, rs = weightedIntersection(rs, r)
+
+
                         
         #assert rs==None or hasattr(rs, 'values') or hasattr(rs, 'keys')
         if rs is None:
@@ -601,6 +612,7 @@
         return used
 
     def searchResults(self, REQUEST=None, used=None, **kw):
+        
         # Get search arguments:
         if REQUEST is None and not kw:
             try: REQUEST=self.REQUEST
@@ -641,6 +653,7 @@
         
         # Perform searches with indexes and sort_index
         r=[]
+        
         used=self._indexedSearch(kw, sort_index, r.append, used)
         if not r:
             return LazyCat(r)