Commit b0f94170 authored by Andreas Jung's avatar Andreas Jung

reverting changes to revision 1.42. Unittests passed in wrong

environment but not on a fresh checkout.
parent 706b9dfe
...@@ -67,9 +67,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -67,9 +67,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
field_name=None, lexicon_id=None): field_name=None, lexicon_id=None):
self.id = id self.id = id
# indexed attributes # Arguments can be passed directly to the constructor or
self._indexed_attrs = getattr(extra, 'doc_attr', '').split(',') or [field_name] or [id] # via the silly "extra" record.
self._indexed_attrs = [ attr.strip() for attr in self._indexed_attrs if attr ] self._fieldname = field_name or getattr(extra, 'doc_attr', '') or id
lexicon_id = lexicon_id or extra.lexicon_id lexicon_id = lexicon_id or extra.lexicon_id
lexicon = getattr(caller, lexicon_id, None) lexicon = getattr(caller, lexicon_id, None)
...@@ -96,9 +96,6 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -96,9 +96,6 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
self.index = self._index_factory(aq_base(self.getLexicon())) self.index = self._index_factory(aq_base(self.getLexicon()))
## Private Methods ## ## Private Methods ##
security.declarePrivate('getLexicon') security.declarePrivate('getLexicon')
...@@ -151,22 +148,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -151,22 +148,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## Pluggable Index APIs ## ## Pluggable Index APIs ##
def index_object(self, documentId, obj, threshold=None): def index_object(self, docid, obj, threshold=None):
""" wrapper to handle indexing of multiple attributes """
# needed for backward compatibility
try: fields = self._indexed_attrs
except: fields = [ self._fieldname ]
res = 0
for attr in fields:
res += self._index_object(documentId, obj, threshold, attr)
return res > 0
def _index_object(self, docid, obj, threshold=None, attr=""):
# XXX We currently ignore subtransaction threshold # XXX We currently ignore subtransaction threshold
text = getattr(obj, attr, None) text = getattr(obj, self._fieldname, None)
if text is None: if text is None:
return 0 return 0
if callable(text): if callable(text):
...@@ -197,7 +181,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -197,7 +181,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
return None return None
tree = QueryParser(self.getLexicon()).parseQuery(query_str) tree = QueryParser(self.getLexicon()).parseQuery(query_str)
results = tree.executeQuery(self.index) results = tree.executeQuery(self.index)
return results, (self.id,) return results, (self._fieldname,)
def getEntryForObject(self, documentId, default=None): def getEntryForObject(self, documentId, default=None):
"""Return the list of words indexed for documentId""" """Return the list of words indexed for documentId"""
...@@ -233,15 +217,15 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -233,15 +217,15 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
def getIndexSourceNames(self): def getIndexSourceNames(self):
"""Return sequence of names of indexed attributes""" """Return sequence of names of indexed attributes"""
try: return [self._fieldname]
return self._indexed_attrs
except:
return [self._fieldname]
def getIndexType(self): def getIndexType(self):
"""Return index type string""" """Return index type string"""
return getattr(self, '_index_type', self._index_factory.__name__) return getattr(self, '_index_type', self._index_factory.__name__)
def getFieldName(self):
"""Return indexed attribute name"""
return self._fieldname
def getLexiconURL(self): def getLexiconURL(self):
"""Return the url of the lexicon used by the index""" """Return the url of the lexicon used by the 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