Commit 2f0191b1 authored by Michel Pelletier's avatar Michel Pelletier

Indexes assumed that if a schema was present to use __getitem__ this

is not the case if an object is passed in to be indexed and does not
support __getitem__
parent c30848e9
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Simple column indices""" """Simple column indices"""
__version__='$Revision: 1.23 $'[11:-2] __version__='$Revision: 1.24 $'[11:-2]
from Globals import Persistent from Globals import Persistent
from BTree import BTree from BTree import BTree
...@@ -210,7 +210,7 @@ class Index(Persistent): ...@@ -210,7 +210,7 @@ class Index(Persistent):
index = self._index index = self._index
id = self.id id = self.id
if self._schema is None: if (self._schema is None) or (obj is not None):
f = getattr f = getattr
else: else:
f = operator.__getitem__ f = operator.__getitem__
...@@ -219,10 +219,14 @@ class Index(Persistent): ...@@ -219,10 +219,14 @@ class Index(Persistent):
if obj is None: if obj is None:
obj = self._data[i] obj = self._data[i]
try:
if self.call_methods: if self.call_methods:
k = f(obj, id)() k = f(obj, id)()
else: else:
k = f(obj, id) k = f(obj, id)
except:
pass
if k is None or k == MV: return if k is None or k == MV: return
......
...@@ -202,7 +202,7 @@ Notes on a new text index design ...@@ -202,7 +202,7 @@ Notes on a new text index design
space. space.
""" """
__version__='$Revision: 1.19 $'[11:-2] __version__='$Revision: 1.20 $'[11:-2]
from Globals import Persistent from Globals import Persistent
import BTree, IIBTree import BTree, IIBTree
...@@ -291,7 +291,7 @@ class TextIndex(Persistent): ...@@ -291,7 +291,7 @@ class TextIndex(Persistent):
if 'obj' is passed in, it is indexed instead of _data[i]""" if 'obj' is passed in, it is indexed instead of _data[i]"""
id = self.id id = self.id
if self._schema is None: if (self._schema is None) or (obj is not None):
f = getattr f = getattr
else: else:
f = operator.__getitem__ f = operator.__getitem__
...@@ -300,12 +300,15 @@ class TextIndex(Persistent): ...@@ -300,12 +300,15 @@ class TextIndex(Persistent):
if obj is None: if obj is None:
obj = self._data[i] obj = self._data[i]
try:
if self.call_methods: if self.call_methods:
k = str(f(obj, id)()) k = str(f(obj, id)())
else: else:
k = str(f(obj, id)) k = str(f(obj, id))
self._index_document(k, i ,un) self._index_document(k, i ,un)
except:
pass
def unindex_item(self, i, obj=None): def unindex_item(self, i, obj=None):
......
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