Commit b9e42f6a authored by Hanno Schlichting's avatar Hanno Schlichting

Whitespace

parent 24e0a976
...@@ -51,7 +51,7 @@ class CatalogError(Exception): ...@@ -51,7 +51,7 @@ class CatalogError(Exception):
pass pass
class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
""" An Object Catalog """ An Object Catalog
An Object Catalog maintains a table of object metadata, and a An Object Catalog maintains a table of object metadata, and a
series of manageable indexes to quickly search for objects series of manageable indexes to quickly search for objects
...@@ -88,7 +88,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -88,7 +88,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self.updateBrains() self.updateBrains()
def __len__(self): def __len__(self):
return self._length() return self._length()
...@@ -96,7 +96,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -96,7 +96,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
""" migration of old __len__ magic for Zope 2.8 """ """ migration of old __len__ magic for Zope 2.8 """
if not hasattr(self, '_length'): if not hasattr(self, '_length'):
n = self.__dict__['__len__']() n = self.__dict__['__len__']()
del self.__dict__['__len__'] del self.__dict__['__len__']
self._length = BTrees.Length.Length(n) self._length = BTrees.Length.Length(n)
def clear(self): def clear(self):
...@@ -284,7 +284,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -284,7 +284,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# New style, get random id # New style, get random id
index=getattr(self, '_v_nextid', 0) index=getattr(self, '_v_nextid', 0)
if index % 4000 == 0: if index % 4000 == 0:
index = randint(-2000000000, 2000000000) index = randint(-2000000000, 2000000000)
while not data.insert(index, newDataRecord): while not data.insert(index, newDataRecord):
index = randint(-2000000000, 2000000000) index = randint(-2000000000, 2000000000)
...@@ -310,7 +310,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -310,7 +310,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if data.get(index, 0) != newDataRecord: if data.get(index, 0) != newDataRecord:
data[index] = newDataRecord data[index] = newDataRecord
return index return index
# the cataloging API # the cataloging API
def catalogObject(self, object, uid, threshold=None, idxs=None, def catalogObject(self, object, uid, threshold=None, idxs=None,
...@@ -395,7 +395,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -395,7 +395,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if not hasattr(self, '_length'): if not hasattr(self, '_length'):
self.migrate__len__() self.migrate__len__()
self._length.change(-1) self._length.change(-1)
else: else:
LOG.error('uncatalogObject unsuccessfully ' LOG.error('uncatalogObject unsuccessfully '
'attempted to uncatalog an object ' 'attempted to uncatalog an object '
...@@ -523,7 +523,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -523,7 +523,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
r, u = r r, u = r
w, rs = weightedIntersection(rs, r) w, rs = weightedIntersection(rs, r)
if not rs: if not rs:
break break
cr.stop() cr.stop()
...@@ -545,16 +545,16 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -545,16 +545,16 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# having a 'values' means we have a data structure with # having a 'values' means we have a data structure with
# scores. Build a new result set, sort it by score, reverse # scores. Build a new result set, sort it by score, reverse
# it, compute the normalized score, and Lazify it. # it, compute the normalized score, and Lazify it.
if not merge: if not merge:
# Don't bother to sort here, return a list of # Don't bother to sort here, return a list of
# three tuples to be passed later to mergeResults # three tuples to be passed later to mergeResults
# note that data_record_normalized_score_ cannot be # note that data_record_normalized_score_ cannot be
# calculated and will always be 1 in this case # calculated and will always be 1 in this case
getitem = self.__getitem__ getitem = self.__getitem__
return [(score, (1, score, rid), getitem) return [(score, (1, score, rid), getitem)
for rid, score in rs.items()] for rid, score in rs.items()]
rs = rs.byValue(0) # sort it by score rs = rs.byValue(0) # sort it by score
max = float(rs[0][0]) max = float(rs[0][0])
...@@ -573,7 +573,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -573,7 +573,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
r.data_record_score_ = score r.data_record_score_ = score
r.data_record_normalized_score_ = int(100. * score / max) r.data_record_normalized_score_ = int(100. * score / max)
return r return r
return LazyMap(getScoredResult, rs, len(rs)) return LazyMap(getScoredResult, rs, len(rs))
elif sort_index is None and not hasattr(rs, 'values'): elif sort_index is None and not hasattr(rs, 'values'):
...@@ -612,13 +612,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -612,13 +612,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if hasattr(rs, 'keys'): if hasattr(rs, 'keys'):
rs = rs.keys() rs = rs.keys()
rlen = len(rs) rlen = len(rs)
if merge and limit is None and ( if merge and limit is None and (
rlen > (len(sort_index) * (rlen / 100 + 1))): rlen > (len(sort_index) * (rlen / 100 + 1))):
# The result set is much larger than the sorted index, # The result set is much larger than the sorted index,
# so iterate over the sorted index for speed. # so iterate over the sorted index for speed.
# This is rarely exercised in practice... # This is rarely exercised in practice...
length = 0 length = 0
try: try:
...@@ -641,7 +641,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -641,7 +641,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
length += len(intset) length += len(intset)
append((k, intset, _self__getitem__)) append((k, intset, _self__getitem__))
# Note that sort keys are unique. # Note that sort keys are unique.
result.sort() result.sort()
if reverse: if reverse:
result.reverse() result.reverse()
...@@ -665,11 +665,11 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -665,11 +665,11 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if reverse: if reverse:
result.reverse() result.reverse()
if limit is not None: if limit is not None:
result = result[:limit] result = result[:limit]
result = LazyValues(result) result = LazyValues(result)
else: else:
return result return result
elif reverse: elif reverse:
# Limit/sort results using N-Best algorithm # Limit/sort results using N-Best algorithm
# This is faster for large sets then a full sort # This is faster for large sets then a full sort
# And uses far less memory # And uses far less memory
...@@ -695,7 +695,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -695,7 +695,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
worst = keys[0] worst = keys[0]
result.reverse() result.reverse()
if merge: if merge:
result = LazyValues(result) result = LazyValues(result)
else: else:
return result return result
elif not reverse: elif not reverse:
...@@ -721,10 +721,10 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -721,10 +721,10 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
n += 1 n += 1
best = keys[-1] best = keys[-1]
if merge: if merge:
result = LazyValues(result) result = LazyValues(result)
else: else:
return result return result
result = LazyMap(self.__getitem__, result, len(result)) result = LazyMap(self.__getitem__, result, len(result))
result.actual_result_count = rlen result.actual_result_count = rlen
return result return result
...@@ -788,7 +788,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -788,7 +788,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
reverse = 1 reverse = 1
# Perform searches with indexes and sort_index # Perform searches with indexes and sort_index
return self.search(args, sort_index, reverse, sort_limit, _merge) return self.search(args, sort_index, reverse, sort_limit, _merge)
__call__ = searchResults __call__ = searchResults
def getCatalogReport(self, query=None): def getCatalogReport(self, query=None):
...@@ -836,11 +836,11 @@ class CatalogSearchArgumentsMap: ...@@ -836,11 +836,11 @@ class CatalogSearchArgumentsMap:
return 0 return 0
else: else:
return 1 return 1
def mergeResults(results, has_sort_keys, reverse): def mergeResults(results, has_sort_keys, reverse):
"""Sort/merge sub-results, generating a flat sequence. """Sort/merge sub-results, generating a flat sequence.
results is a list of result set sequences, all with or without sort keys results is a list of result set sequences, all with or without sort keys
""" """
if not has_sort_keys: if not has_sort_keys:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment