[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/common - UnIndex.py:1.15.14.2
Andreas Jung
andreas@andreas-jung.com
Tue, 26 Nov 2002 12:17:44 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/common
In directory cvs.zope.org:/tmp/cvs-serv16687/common
Modified Files:
Tag: ajung-oneindex-multipleattributes-branch
UnIndex.py
Log Message:
added multi-attribute indexing support for UnIndex base class and FieldIndex
=== Zope/lib/python/Products/PluginIndexes/common/UnIndex.py 1.15.14.1 => 1.15.14.2 ===
--- Zope/lib/python/Products/PluginIndexes/common/UnIndex.py:1.15.14.1 Sun Nov 17 06:14:57 2002
+++ Zope/lib/python/Products/PluginIndexes/common/UnIndex.py Tue Nov 26 12:17:43 2002
@@ -38,7 +38,7 @@
"""UnIndex object interface"""
- def __init__(self, id, ignore_ex=None, call_methods=None):
+ def __init__(self, id, ignore_ex=None, call_methods=None, extra=None, caller=None):
"""Create an unindex
UnIndexes are indexes that contain two index components, the
@@ -75,10 +75,15 @@
self.ignore_ex=ignore_ex # currently unimplimented
self.call_methods=call_methods
- # experimental code for specifing the operator
- self.operators = ['or','and']
+ self.operators = ('or', 'and')
self.useOperator = 'or'
+ # allow index to index multiple attributes
+ try:
+ self.indexed_attrs = extra.indexed_attrs.split(',')
+ self.indexed_attrs = [ attr.strip() for attr in self.indexed_attrs if attr ]
+ except: self.indexed_attrs = [ self.id ]
+
self.__len__=BTrees.Length.Length() # see __len__ method docstring
self.clear()
@@ -214,13 +219,28 @@
indexRow=IITreeSet((indexRow, documentId))
self._index[entry] = indexRow
+
def index_object(self, documentId, obj, threshold=None):
+ """ wrapper to handle indexing of multiple attributes """
+
+ # needed for backward compatibility
+ try: fields = self.indexed_attrs
+ except: fields = [ self.id ]
+
+ res = 0
+ for attr in fields:
+ res += self._index_object(documentId, obj, threshold, attr)
+
+ return res > 0
+
+
+ def _index_object(self, documentId, obj, threshold=None, attr=''):
""" index and object 'obj' with integer id 'documentId'"""
global _marker
returnStatus = 0
# First we need to see if there's anything interesting to look at
- datum = self._get_object_datum(obj)
+ datum = self._get_object_datum(obj, attr)
# We don't want to do anything that we don't have to here, so we'll
# check to see if the new and existing information is the same.
@@ -244,12 +264,12 @@
return returnStatus
- def _get_object_datum(self,obj):
+ def _get_object_datum(self,obj, attr):
# self.id is the name of the index, which is also the name of the
# attribute we're interested in. If the attribute is callable,
# we'll do so.
try:
- datum = getattr(obj, self.id)
+ datum = getattr(obj, attr)
if callable(datum):
datum = datum()
except AttributeError:
@@ -393,6 +413,13 @@
""" return name of indexed attributes """
return (self.id, )
+ def getIndexSourceNames(self):
+ """ return sequence of indexed attributes """
+
+ try:
+ return self.indexed_attrs
+ except:
+ return [ self.id ]
def uniqueValues(self, name=None, withLengths=0):
"""\