[Zope3-checkins] CVS: Zope3/src/zope/fieldindex - fieldindex.py:1.4
Andreas Jung
andreas@andreas-jung.com
Thu, 27 Mar 2003 04:28:37 -0500
Update of /cvs-repository/Zope3/src/zope/fieldindex
In directory cvs.zope.org:/tmp/cvs-serv12061
Modified Files:
fieldindex.py
Log Message:
sequences of values can not be passed to search() to allow a search
on multiple values. The results of the subsearches are combined using OR.
=== Zope3/src/zope/fieldindex/fieldindex.py 1.3 => 1.4 ===
--- Zope3/src/zope/fieldindex/fieldindex.py:1.3 Wed Mar 26 10:46:28 2003
+++ Zope3/src/zope/fieldindex/fieldindex.py Thu Mar 27 04:28:36 2003
@@ -20,9 +20,11 @@
from zodb.btrees.IOBTree import IOBTree
from zodb.btrees.OOBTree import OOBTree
-from zodb.btrees.IIBTree import IITreeSet, IISet
+from zodb.btrees.IIBTree import IITreeSet, IISet, union
from zope.fieldindex.ifieldindex import IFieldIndex
+from types import ListType, TupleType
+
class FieldIndex(Persistent):
@@ -77,14 +79,32 @@
self._fwd_index[value].remove(docid)
if len(self._fwd_index[value]) == 0:
del self._fwd_index[value]
- except:
- pass
+ except: pass
- def search(self, value):
+ def search(self, values):
- try:
- return IISet(self._fwd_index[value])
- except KeyError:
- return IISet()
+
+ # values can either be a single value or a sequence of
+ # values to be searched.
+
+ if isinstance(values , (ListType, TupleType)):
+
+ result = IISet()
+
+ for value in values:
+
+ try: r = IISet(self._fwd_index[value])
+ except KeyError: continue
+
+ # the results of all subsearches are combined using OR
+ result = union(result, r)
+
+ else:
+
+ try: result = IISet(self._fwd_index[values])
+ except: result = IISet()
+
+
+ return result