Commit 1f2babb5 authored by Andreas Jung's avatar Andreas Jung

re-added multiple attribute support - all unit tests pass

parent 989e3d5e
......@@ -70,6 +70,8 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
# 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
self._indexed_attrs = self._fieldname.split(',')
self._indexed_attrs = [ attr.strip() for attr in self._indexed_attrs if attr ]
lexicon_id = lexicon_id or extra.lexicon_id
lexicon = getattr(caller, lexicon_id, None)
......@@ -148,7 +150,20 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## Pluggable Index APIs ##
def index_object(self, docid, obj, threshold=None):
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
def _index_object(self, docid, obj, threshold=None, attr=None):
# XXX We currently ignore subtransaction threshold
text = getattr(obj, self._fieldname, None)
if text is None:
......@@ -181,7 +196,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
return None
tree = QueryParser(self.getLexicon()).parseQuery(query_str)
results = tree.executeQuery(self.index)
return results, (self._fieldname,)
return results, (self.id,)
def getEntryForObject(self, documentId, default=None):
"""Return the list of words indexed for documentId"""
......@@ -217,16 +232,15 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
def getIndexSourceNames(self):
"""Return sequence of names of indexed attributes"""
return [self._fieldname]
try:
return self._indexed_attrs
except:
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"""
try:
......
......@@ -32,10 +32,11 @@ from the most relevant to the least relevant.
<tr>
<td align="left" valign="top">
<div class="form-label">
Field name
Indexed attributes
</div></td>
<td align="left" valign="top">
<input type="text" name="extra.doc_attr:record" size="40" />
<em>attribute1,attribute2,...</em> or leave empty
</td>
</tr>
......
......@@ -2,8 +2,8 @@
<dtml-var manage_tabs>
<p class="form-help">
Name of attribute indexed:
<em>&dtml-getFieldName;</em>
Name(s) of attribute(s) indexed:
<em><dtml-var "', '.join(getIndexSourceNames())"></em>
</p>
<p class="form-help">
Index type:
......
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