Commit c2146c7a authored by Gary Poster's avatar Gary Poster

Fix TopicIndex in two ways:

1) items added to a topic index PythonFilteredSet could never be removed upon a reindex, even if they no longer evaluated to be true.  This is fixed.
2) Casey informs me that a IITreeSet is better for this application that an IISet.  This should be a transparent change simply by relying on the keys method, which both have, rather than the iterable IISet.
parent cd1e8265
......@@ -11,9 +11,10 @@
#
##############################################################################
__version__ = '$Id: FilteredSet.py,v 1.5 2003/06/12 14:36:47 andreasjung Exp $'
__version__ = '$Id: FilteredSet.py,v 1.6 2003/12/31 21:18:03 poster Exp $'
from BTrees.IIBTree import IISet
from ZODB.POSException import ConflictError
from BTrees.IIBTree import IITreeSet
from Persistence import Persistent
from Globals import DTMLFile
from zLOG import WARNING,LOG
......@@ -29,7 +30,7 @@ class FilteredSetBase(Persistent):
def clear(self):
self.ids = IISet()
self.ids = IITreeSet()
def index_object(self, documentId, obj):
......@@ -41,10 +42,17 @@ class FilteredSetBase(Persistent):
except KeyError: pass
def getId(self): return self.id
def getExpression(self): return self.expr
def getIds(self): return self.ids
def getType(self): return self.meta_type
def getId(self):
return self.id
def getExpression(self):
return self.expr
def getIds(self):
return self.ids
def getType(self):
return self.meta_type
def setExpression(self, expr): self.expr = expr
......@@ -60,9 +68,16 @@ class PythonFilteredSet(FilteredSetBase):
meta_type = 'PythonFilteredSet'
def index_object(self, documentId, o):
try:
if eval(self.expr): self.ids.insert(documentId)
if eval(self.expr): # XXX trusted code!
self.ids.insert(documentId)
else:
try:
self.ids.remove(documentId)
except KeyError:
pass
except ConflictError:
raise
except:
LOG('FilteredSet',WARNING,'eval() failed',\
'Object: %s, expr: %s' % (o.getId(),self.expr),\
......
......@@ -11,7 +11,7 @@
#
##############################################################################
__version__ = '$Id: TopicIndex.py,v 1.15 2003/11/21 13:48:11 andreasjung Exp $'
__version__ = '$Id: TopicIndex.py,v 1.16 2003/12/31 21:18:03 poster Exp $'
from Globals import Persistent, DTMLFile
from OFS.SimpleItem import SimpleItem
......@@ -100,7 +100,7 @@ class TopicIndex(Persistent, SimpleItem):
res = set_func(res,rows)
if res:
return res, (self.id,)
return res.keys(), (self.id,)
else:
return IISet(), (self.id,)
......
......@@ -34,7 +34,6 @@ class TestBase(unittest.TestCase):
return self._search(query,'or',expected)
def _search(self,query,operator,expected):
res = self.TI._apply_index({'topic':{'query':query,'operator':operator}})
rows = list(res[0])
rows.sort()
......@@ -72,6 +71,11 @@ class TestTopicIndex(TestBase):
self._searchAnd('doc2',[3,4])
self._searchAnd(['doc2'],[3,4])
self._searchAnd(['doc1','doc2'],[])
def testRemoval(self):
self.TI.index_object(1, Obj('1','doc2'))
self._searchOr('doc1',[2])
self._searchOr('doc2', [1,3,4])
def test_suite():
......
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