[Zope-Checkins] CVS: Zope2 - UnIndex.py:1.23.2.2.6.10
Jim Fulton
jim@digiciool.com
Mon, 12 Mar 2001 11:42:51 -0500 (EST)
Update of /cvs-repository/Zope2/lib/python/SearchIndex
In directory korak:/tmp/cvs-serv26972
Modified Files:
Tag: Catalog-BTrees-Integration
UnIndex.py
Log Message:
Added optimization for indexes with one key per value. If
a key has just one value, we store the document id directly,
rather than a set.
--- Updated File UnIndex.py in package Zope2 --
--- UnIndex.py 2001/03/11 03:05:51 1.23.2.2.6.9
+++ UnIndex.py 2001/03/12 16:42:50 1.23.2.2.6.10
@@ -100,7 +100,7 @@
from BTrees.OOBTree import OOBTree
from BTrees.IOBTree import IOBTree
-from BTrees.IIBTree import IISet, IITreeSet, union
+from BTrees.IIBTree import IITreeSet, IISet, union
import BTrees.Length
import sys
@@ -170,7 +170,14 @@
_index=self._index
self._index=OOBTree()
- convert(_index, self._index, threshold, IITreeSet)
+
+ def convertSet(s, IITreeSet=IITreeSet):
+ if len(s) == 1:
+ try: return s[0] # convert to int
+ except: pass # This is just an optimization.
+ return IITreeSet(s)
+
+ convert(_index, self._index, threshold, convertSet)
_unindex=self._unindex
self._unindex=IOBTree()
@@ -228,6 +235,11 @@
del self._index[entry]
try: self.__len__.change(-1)
except AttributeError: pass # pre-BTrees-module instance
+ except AttributeError:
+ # index row is an int
+ del self._index[entry]
+ try: self.__len__.change(-1)
+ except AttributeError: pass # pre-BTrees-module instance
except:
LOG(self.__class__.__name__, ERROR,
('unindex_object could not remove '
@@ -253,12 +265,15 @@
# Make sure there's actually a row there already. If not, create
# an IntSet and stuff it in first.
if indexRow is _marker:
- self._index[entry] = indexRow = IITreeSet()
+ self._index[entry] = documentId
try: self.__len__.change(1)
except AttributeError: pass # pre-BTrees-module instance
-
- indexRow.insert(documentId)
-
+ else:
+ try: indexRow.insert(documentId)
+ except AttributeError:
+ # index row is an int
+ indexRow=IITreeSet((indexRow, documentId))
+ self._index[entry] = indexRow
def index_object(self, documentId, obj, threshold=None):
""" index and object 'obj' with integer id 'documentId'"""
@@ -308,7 +323,7 @@
LOG('UnIndex', ERROR, 'Attempt to unindex nonexistent document'
' with id %s' % documentId)
- def _apply_index(self, request, cid=''):
+ def _apply_index(self, request, cid='', type=type, None=None):
"""Apply the index to query parameters given in the argument,
request
@@ -345,6 +360,7 @@
r = None
anyTrue = 0
opr = None
+ IntType=type(1)
if request.has_key(id+'_usage'):
# see if any usage params are sent to field
@@ -375,10 +391,15 @@
for key in keys:
if nonEmpty(key):
anyTrue = 1
- set=get(key)
+ set=get(key, None)
if set is not None:
r = union(r, set)
-
+
+ if type(r) is IntType: r=IISet((r,))
+ if r:
+ return r, (id,)
+
+
if r is None:
if anyTrue:
r=IISet()