Commit cb47ec84 authored by Toby Dickenson's avatar Toby Dickenson

merged toby-subclass-index-branch: Collector 284: KeywordIndex and FieldIndex subclassing

parent 69440268
......@@ -62,12 +62,7 @@ class KeywordIndex(UnIndex,PluggableIndex.PluggableIndex,Persistent,
# attribute we're interested in. If the attribute is callable,
# we'll do so.
newKeywords = getattr(obj, self.id, ())
if callable(newKeywords):
newKeywords = newKeywords()
if type(newKeywords) is StringType:
newKeywords = (newKeywords, )
newKeywords = self._get_object_keywords(obj)
oldKeywords = self._unindex.get(documentId, None)
......@@ -96,6 +91,14 @@ class KeywordIndex(UnIndex,PluggableIndex.PluggableIndex,Persistent,
self.insertForwardIndexEntry(kw, documentId)
return 1
def _get_object_keywords(self,obj):
newKeywords = getattr(obj, self.id, ())
if callable(newKeywords):
newKeywords = newKeywords()
if hasattr(newKeywords,'capitalize'): # is it string-like ?
newKeywords = (newKeywords, )
return newKeywords
def unindex_objectKeywords(self, documentId, keywords):
""" carefully unindex the object with integer id 'documentId'"""
......
......@@ -13,7 +13,7 @@
"""Simple column indices"""
__version__='$Revision: 1.7 $'[11:-2]
__version__='$Revision: 1.8 $'[11:-2]
from Globals import Persistent
from Acquisition import Implicit
......@@ -216,16 +216,8 @@ class UnIndex(Persistent, Implicit):
returnStatus = 0
# First we need to see if there's anything interesting to look at
# 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)
if callable(datum):
datum = datum()
except AttributeError:
datum = _marker
datum = self._get_object_datum(obj)
# 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.
oldDatum = self._unindex.get(documentId, _marker)
......@@ -241,6 +233,18 @@ class UnIndex(Persistent, Implicit):
return returnStatus
def _get_object_datum(self,obj):
# 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)
if callable(datum):
datum = datum()
except AttributeError:
datum = _marker
return datum
def numObjects(self):
""" return number of indexed objects """
return len(self._index)
......
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