[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog - Catalog.py:1.82.2.1 CatalogAwarenessInterface.py:1.2.160.1 ZCatalog.py:1.103.2.1
Casey Duncan
casey@zope.com
Wed, 27 Mar 2002 15:51:52 -0500
Update of /cvs-repository/Zope/lib/python/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv22094/lib/python/Products/ZCatalog
Modified Files:
Tag: casey-death_to_index_html-branch
Catalog.py CatalogAwarenessInterface.py ZCatalog.py
Log Message:
Updating branch to head for testing
=== Zope/lib/python/Products/ZCatalog/Catalog.py 1.82 => 1.82.2.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:
# return everything
@@ -480,16 +480,7 @@
rs=data.items()
append(LazyMap(self.instantiate, rs, len(self)))
else:
- try:
- for k, intset in sort_index.items():
- if hasattr(intset, 'keys'): intset=intset.keys()
- append((k,LazyMap(self.__getitem__, intset)))
- except AttributeError:
- raise ValueError, (
- "Incorrect index name passed as"
- " 'sort_on' parameter. Note that you may only"
- " sort on values for which there is a matching"
- " index available.")
+ self._build_sorted_results(data,sort_index,append)
elif rs:
# this is reached by having an empty result set (ie non-None)
if sort_index is None and hasattr(rs, 'values'):
@@ -513,28 +504,47 @@
# reached, therefor 'sort-on' does not happen in the
# context of text index query. This should probably
# sort by relevance first, then the 'sort-on' attribute.
- if ((len(rs) / 4) > len(sort_index)):
- # if the sorted index has a quarter as many keys as
- # the result set
- for k, intset in sort_index.items():
- # We have an index that has a set of values for
- # each sort key, so we interset with each set and
- # get a sorted sequence of the intersections.
-
- # This only makes sense if the number of
- # keys is much less then the number of results.
- intset = intersection(rs, intset)
- if intset:
- if hasattr(intset, 'keys'): intset=intset.keys()
- append((k,LazyMap(self.__getitem__, intset)))
- else:
- if hasattr(rs, 'keys'): rs=rs.keys()
- for did in rs:
- append((sort_index.keyForDocument(did),
- LazyMap(self.__getitem__,[did])))
+ self._build_sorted_results(rs,sort_index,append)
return used
+ def _build_sorted_results(self,rs,sort_index,append):
+ # The two 'for' loops in here contribute a significant
+ # proportion of the time to perform an indexed search.
+ # Try to avoid all non-local attribute lookup inside
+ # those loops.
+ _lazymap = LazyMap
+ _intersection = intersection
+ _self__getitem__ = self.__getitem__
+ _None = None
+ if ((len(rs) / 4) > len(sort_index)):
+ # if the sorted index has a quarter as many keys as
+ # the result set
+ for k, intset in sort_index.items():
+ # We have an index that has a set of values for
+ # each sort key, so we interset with each set and
+ # get a sorted sequence of the intersections.
+
+ # This only makes sense if the number of
+ # keys is much less then the number of results.
+ intset = _intersection(rs, intset)
+ if intset:
+ keys = getattr(intset,'keys',_None)
+ if keys is not _None:
+ # Is this ever true?
+ intset = keys()
+ append((k,_lazymap(_self__getitem__, intset)))
+ else:
+ if hasattr(rs, 'keys'): rs=rs.keys()
+ _sort_index_keyForDocument = sort_index.keyForDocument
+ _keyerror = KeyError
+ for did in rs:
+ try:
+ append((_sort_index_keyForDocument(did),
+ _lazymap(_self__getitem__,[did])))
+ except _keyerror:
+ pass
+
def searchResults(self, REQUEST=None, used=None, **kw):
# Get search arguments:
@@ -595,7 +605,7 @@
so.lower() in ('reverse', 'descending')):
r.reverse()
- r=map(lambda i: i[1], r)
+ r= [i[1] for i in r]
r=LazyCat(r, reduce(lambda x,y: x+len(y), r, 0))
return r
=== Zope/lib/python/Products/ZCatalog/CatalogAwarenessInterface.py 1.2 => 1.2.160.1 ===
"""
- def creator(self):
+ def creator():
"""
Return a sequence of user names who have the local Owner role
@@ -14,7 +14,7 @@
"""
- def summary(self, num=200):
+ def summary(num=200):
"""
Returns the summary of the text contents of the object (if
@@ -22,7 +22,7 @@
"""
- def index_object(self):
+ def index_object():
"""
This object will try and catalog itself when this method is
@@ -30,7 +30,7 @@
"""
- def unindex_object(self):
+ def unindex_object():
"""
This object will try and uncatalog itself when this method is
@@ -38,7 +38,7 @@
"""
- def reindex_all(self, obj=None):
+ def reindex_all(obj=None):
"""
This method will cause this object to get reindexed. If this
=== Zope/lib/python/Products/ZCatalog/ZCatalog.py 1.103 => 1.103.2.1 ===
from Products.PluginIndexes.TextIndex import Splitter
import urllib, os, sys, time, types
-
+import string
manage_addZCatalogForm=DTMLFile('dtml/addZCatalog',globals())
@@ -473,7 +473,7 @@
"A cataloged object must support the 'getPhysicalPath' "
"method if no unique id is provided when cataloging"
)
- else: uid=string.join(uid(), '/')
+ else: uid='/'.join(uid())
elif not isinstance(uid,types.StringType):
raise CatalogError('The object unique id must be a string.')
@@ -682,7 +682,7 @@
and
(not obj_searchterm or
(hasattr(ob, 'PrincipiaSearchSource') and
- string.find(ob.PrincipiaSearchSource(), obj_searchterm) >= 0
+ ob.PrincipiaSearchSource().find(obj_searchterm) >= 0
))
and
(not obj_expr or expr_match(ob, obj_expr))
@@ -719,7 +719,7 @@
No exceptions are raised.
"""
script=REQUEST.script
- if string.find(path, script) != 0:
+ if path.find(script) != 0:
path='%s/%s' % (script, path)
try: return REQUEST.resolve_url(path)
except: pass
@@ -755,7 +755,7 @@
if ob is None:
removed.append(path)
continue
- ppath = string.join(ob.getPhysicalPath(), '/')
+ ppath = '/'.join(ob.getPhysicalPath())
if path != ppath:
fixed.append((path, ppath))
else: