From 5cc2079c6eb3f53cc95d5d6b1a6439f5d6544e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 3 Feb 2012 19:35:13 +0100 Subject: [PATCH] index more than one contact per field --- themis/search/indexer.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/themis/search/indexer.py b/themis/search/indexer.py index 15bc32f..25d0ec7 100644 --- a/themis/search/indexer.py +++ b/themis/search/indexer.py @@ -196,18 +196,25 @@ def contactFuzzyIndexer(obj): v = getattr(obj, attr) if not v: continue - v = v[0] - if ':' in v: - src = ContactsSource() - try: - r = src.fastGetTitleByToken(obj, v) - except KeyError: - return v.split(':')[1:] - if not type(r) is unicode: - r = unicode(r, 'utf-8') - return r - else: - return v + + # it may happen there are several items, merge all of them into a + # single value + result = [] + for contact in v: + if ':' in contact: + src = ContactsSource() + try: + r = src.fastGetTitleByToken(obj, contact) + except KeyError: + result.append(contact.split(':')[1:]) + continue + if not type(r) is unicode: + r = unicode(r, 'utf-8') + result.append(r) + else: + result.append(contact) + if result: + return u' '.join(result) return None grok.global_adapter(contactFuzzyIndexer, name="mailContactFuzzy")