Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
reverting changes to revision 1.42. Unittests passed in wrong
Browse files Browse the repository at this point in the history
environment but not on a fresh checkout.
  • Loading branch information
zopyx committed Feb 2, 2003
1 parent 8d83236 commit 1181f49
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions ZCTextIndex.py
Expand Up @@ -67,9 +67,9 @@ def __init__(self, id, extra=None, caller=None, index_factory=None,
field_name=None, lexicon_id=None):
self.id = id

# indexed attributes
self._indexed_attrs = getattr(extra, 'doc_attr', '').split(',') or [field_name] or [id]
self._indexed_attrs = [ attr.strip() for attr in self._indexed_attrs if attr ]
# Arguments can be passed directly to the constructor or
# via the silly "extra" record.
self._fieldname = field_name or getattr(extra, 'doc_attr', '') or id

lexicon_id = lexicon_id or extra.lexicon_id
lexicon = getattr(caller, lexicon_id, None)
Expand All @@ -96,9 +96,6 @@ def __init__(self, id, extra=None, caller=None, index_factory=None,

self.index = self._index_factory(aq_base(self.getLexicon()))




## Private Methods ##

security.declarePrivate('getLexicon')
Expand Down Expand Up @@ -151,22 +148,9 @@ def query(self, query, nbest=10):

## Pluggable Index APIs ##

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._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=""):
def index_object(self, docid, obj, threshold=None):
# XXX We currently ignore subtransaction threshold
text = getattr(obj, attr, None)
text = getattr(obj, self._fieldname, None)
if text is None:
return 0
if callable(text):
Expand Down Expand Up @@ -197,7 +181,7 @@ def _apply_index(self, request, cid=''):
return None
tree = QueryParser(self.getLexicon()).parseQuery(query_str)
results = tree.executeQuery(self.index)
return results, (self.id,)
return results, (self._fieldname,)

def getEntryForObject(self, documentId, default=None):
"""Return the list of words indexed for documentId"""
Expand Down Expand Up @@ -233,15 +217,15 @@ def clear(self):

def getIndexSourceNames(self):
"""Return sequence of names of indexed attributes"""
try:
return self._indexed_attrs
except:
return [self._fieldname]
return [self._fieldname]

def getIndexType(self):
"""Return index type string"""
return getattr(self, '_index_type', self._index_factory.__name__)

def getFieldName(self):
"""Return indexed attribute name"""
return self._fieldname

def getLexiconURL(self):
"""Return the url of the lexicon used by the index"""
Expand Down

0 comments on commit 1181f49

Please sign in to comment.