[Zope-Checkins] CVS: Zope2 - UnIndex.py:1.23.2.7.2.2
chrism@serenade.digicool.com
chrism@serenade.digicool.com
Tue, 17 Apr 2001 02:46:25 -0400
Update of /cvs-repository/Zope2/lib/python/SearchIndex
In directory serenade.digicool.com:/home/chrism/sandboxes/CatalogForNow/lib/python/SearchIndex
Modified Files:
Tag: chrism-CatalogForNow-branch
UnIndex.py
Log Message:
Fixed some problems that surfaced via Jim's single-element-sequence space optimization.
--- Updated File UnIndex.py in package Zope2 --
--- UnIndex.py 2001/04/12 22:44:41 1.23.2.7.2.1
+++ UnIndex.py 2001/04/17 06:46:25 1.23.2.7.2.2
@@ -91,12 +91,11 @@
from Acquisition import Implicit
import BTree
import IOBTree
-import operator
-import string, pdb
+import string
from zLOG import LOG, ERROR
-from types import *
+from types import StringType, ListType, IntType, TupleType
-from BTrees.OOBTree import OOBTree
+from BTrees.OOBTree import OOBTree, OOSet
from BTrees.IOBTree import IOBTree
from BTrees.IIBTree import IITreeSet, IISet, union
import BTrees.Length
@@ -105,15 +104,6 @@
_marker = []
-def nonEmpty(s):
- "returns true if a non-empty string or any other (nonstring) type"
- if type(s) is StringType:
- if s: return 1
- else: return 0
- else:
- return 1
-
-
class UnIndex(Persistent, Implicit):
"""UnIndex object interface"""
@@ -132,6 +122,10 @@
self._index = {datum:[documentId1, documentId2]}
self._unindex = {documentId:datum}
+ If any item in self._index has a length-one value, the value is an
+ integer, and not a set. There are special cases in the code to deal
+ with this.
+
The arguments are:
'id' -- the name of the item attribute to index. This is
@@ -207,8 +201,12 @@
elements found at each point in the index."""
histogram = {}
- for (key, value) in self._index.items():
- entry = len(value)
+ for item in self._index.items():
+ if type(item) is IntType:
+ entry = 1 # "set" length is 1
+ else:
+ key, value = item
+ entry = len(value)
histogram[entry] = histogram.get(entry, 0) + 1
return histogram
@@ -401,16 +399,20 @@
setlist = index.items(lo)
for k, set in setlist:
+ if type(set) is IntType:
+ set = IISet((set,))
r = union(r, set)
else: # not a range search
for key in keys:
set=index.get(key, None)
if set is not None:
+ if type(set) is IntType:
+ set = IISet((set,))
r = union(r, set)
- if type(r) is type(1): r=IISet((r,))
+ if type(r) is IntType: r=OOSet((r,))
if r is None:
- return IISet(), (id,)
+ return OOSet(), (id,)
else:
return r, (id,)
@@ -440,8 +442,7 @@
rl=[]
for i in self._index.keys():
set = self._index[i]
- if type(set) is type(1):
- # bleah
+ if type(set) is IntType:
l = 1
else:
l = len(set)
@@ -451,5 +452,11 @@
def keyForDocument(self, id):
return self._unindex[id]
- def items(self): return self._index.items()
+ def items(self):
+ items = []
+ for k,v in self._index.items():
+ if type(v) is IntType:
+ v = IISet((v,))
+ items.append((k, v))
+ return items